WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 14 months ago

#16734 new enhancement

Allowing multiple selection when using wp_dropdown_* functions

Reported by: grandslambert Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.1
Component: Taxonomy Keywords: needs-patch 2nd-opinion
Focuses: Cc:

Description (last modified by wonderboymusic)

I would like to be able to pass an argument to wp_dropdown_categories() to allow the user to select more than one category using a CTRL-CLICK. I can use a preg_replace to add the multiple tag to the html select tag, but I cannot pass multiple selections in the "selected" argument.

Attachments (4)

category-template.php.diff (1.6 KB) - added by grandslambert 5 years ago.
Change in the category-template.php to support multipe select boxes.
wp-admin.css.diff (115.1 KB) - added by grandslambert 5 years ago.
Change in the wp-admin.css to add a class to make the multiple select taller.
16734.diff (2.9 KB) - added by wonderboymusic 15 months ago.
16734.2.diff (4.0 KB) - added by DrewAPicture 14 months ago.
docs

Download all attachments as: .zip

Change History (21)

@grandslambert5 years ago

Change in the category-template.php to support multipe select boxes.

@grandslambert5 years ago

Change in the wp-admin.css to add a class to make the multiple select taller.

comment:1 @greuben5 years ago

I don't know how useful this feature will be but for css and javascript files you need to submit a patch using their respective .dev files.

comment:2 @grandslambert5 years ago

I am working on some plugins and want people to be able to select multiple categories. I tried to use the checkboxes like on the post page but there does not seem to be a really useful method for creating those that I can find. I played around with wp_terms_checklist() but could not get it to accept my selected categories - it just checked whatever it felt like checking. I need to use this in a widget form.

comment:3 @prionkor4 years ago

@grandslambert: Ability to have multiple selection should be added. I am absolutely with you!

The feature can be something like adding an extra argument array which we can call attribute array. This way we can add id, classes, multiple or any other attribute on the select field.

Last edited 4 years ago by prionkor (previous) (diff)

comment:4 @prionkor4 years ago

  • Keywords dev-feedback added
  • Version changed from 3.1 to 3.3

comment:5 @SergeyBiryukov4 years ago

  • Version changed from 3.3 to 3.1

Version field indicates when the enhancement was initially suggested.

comment:6 @Gecka4 years ago

Dear Wordpress Core "Devs",

You really know how to discourage developers to contribute to wordpress. Well done. I found so many little fixes or small nifty additions that never got their way into core or have been rewritten by you, letting behind the original author credit.

The world should know about that!

Regards

BTW WP is a great product, I really hope that one day some will fork that project over github and will allow contributing!

comment:7 @mbijon4 years ago

(troll-bait taken, admins feel free to delete this comment that has nothing to do with the ticket)

@Gecka, I think the extra discussion that happens here on Trac is vital to keeping WordPress stable and promulgating best practices. Whether core is in SVN or Git it's the discussions here that often refine, change or keep code out of core. And, while there are tools that might be able to parallel what happens on Trac, those are GitHub-specific and not general Git tools.

Besides the core team is working to reduce the hurdles to contributing:

comment:8 @nacin20 months ago

  • Component changed from General to Taxonomy

comment:9 @wonderboymusic16 months ago

#24731 was marked as a duplicate.

@wonderboymusic15 months ago

comment:10 @wonderboymusic15 months ago

  • Description modified (diff)
  • Keywords dev-feedback removed
  • Milestone changed from Awaiting Review to 4.0
  • Summary changed from Allowing multiple selection when using wp_dropdown_categories to Allowing multiple selection when using wp_dropdown_* functions

16734.diff adds 'multiple' => false to the default args for wp_dropdown_(categories|pages|users)().

No instances in core use this, but it will allow users to have multiple-select for whatever their little hearts desire.

comment:11 @DrewAPicture15 months ago

  • Keywords needs-docs added

comment:12 @prionkor15 months ago

I am glad, after 3 years. Looks like this change is going to make it to the core! :)

comment:13 @ircbot14 months ago

This ticket was mentioned in IRC in #wordpress-dev by helen. View the logs.

comment:14 @helen14 months ago

  • Keywords needs-patch added; has-patch removed

I like this, despite it making the function name of "dropdown" a little fuzzy. Needs a patch that accounts for an array of values for selected(), though. And in the next couple days, or we'll have to punt once we hit beta.

comment:15 @prionkor14 months ago

I was wondering if a array of key values pair could be passed which later becomes attribute value pair. We could introduce a new attribute key.

For example

$args = array(
        'orderby'            => 'ID', 
	'order'              => 'ASC',
	'show_count'         => 0,
	'hide_empty'         => 1, 
	'child_of'           => 0,
	'exclude'            => '',
	'echo'               => 1,
	'selected'           => 0,
	'hierarchical'       => 0, 
        'attributes' => array(
                              'multiple' => 'multiple',
                              'data-name' => 'datavalue1'
                              'data-name2' => 'datavalue2'
                        )
);


wp_dropdown_categories($args);

This would be helpful if we want to pass custom attributes like data-.

@DrewAPicture14 months ago

docs

comment:16 @DrewAPicture14 months ago

  • Keywords needs-docs removed

16734.2.diff adds docs. Still doesn't account for an array of values in selected() as requested in comment:14.

comment:17 @nacin14 months ago

  • Keywords 2nd-opinion added
  • Milestone changed from 4.0 to Future Release

As already stated, because <select multiple> have issues with <option selected> at least in terms of this API, I think we need to avoid touching this for the moment, until we have that resolved. Ultimately, this hasn't had enough forethought put into it for it to squeeze into 4.0 on the eve of beta.

Modifying selected() to handle an array possibly has compatibility issues (though it's possible it's fine). We might need to handle it some other way. selected( in_array( $option, $selected ) ) is fine, as long as $selected is forced to be an array when not multiple.

Bigger question unresolved: <select multiple> is a terrible experience; why would anyone want to inflict that on their users? Since this ticket has been released, browsers have added improved support for various new HTML5 inputs, notably not multiple selects, while new multi-selection libraries have come out like Chosen and Select2. I hesitate allowing WordPress APIs to hackily support something that is well known to be a poor user experience.

Note: See TracTickets for help on using tickets.