Opened 13 years ago
Closed 13 years ago
#20679 closed defect (bug) (worksforme)
Widget with mutliple select doesn't work
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.3.2 |
Component: | Widgets | Keywords: | needs-patch |
Focuses: | Cc: |
Description
Widget with <select multiple="multiple"> doesn't work.
To reproduce the bug you need to test the following code in a widget:
public function update($new_instance, $old_instance) { print_r($new_instance); die(); } function form($instance) { ?> <select multiple="multiple" name="<?php echo $this->get_field_name('options'); ?>"> <option value="1"> Option 1 </option> <option value="2"> Option 2 </option> </option> </select> <?php }
Change History (8)
#2
@
13 years ago
FWIW the multiple select element is a very poor element from a UI and UX perspective. I can guarantee you'll get users who don't know how to select multiple items in it. You might be better off replacing it with checkboxes which are much more widely used and understood.
#3
@
13 years ago
Yes here are more details:
Post parameters when saving are:
action save-widget add_new id_base featuredgames multi_number savewidgets b277827e4e sidebar left-sidebar-home-page widget-featuredgames[2][categoriesIds] 7 widget-featuredgames[2][categoriesIds] 8 widget-height 200 widget-id featuredgames-2 widget-width 250 widget_number 2
As you can see categoriesIds should be an array from the multiple select.
I am expecting to get from the update function an array containing both submitted values:
public function update($new_instance, $old_instance) { print_r($new_instance); die(); }
And it actually returns this:
Array ( [categoriesIds] => 8 )
I agree, dd32, it maybe not the best UI option but still it it's the fastest way
to achieve it...
#4
@
13 years ago
What johnbillion said. Do we have a widget with multiselect? If so, it's an oversight on my part or I would have booted it long ago for that reason. Checkboxes are the approved multi-select UI in the WP admin.
#5
@
13 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
What Jane said. We do not use multiselect anywhere in WP and we should not encourage plugin authors to use them either. Checkboxes FTW.
#6
follow-up:
↓ 8
@
13 years ago
- Cc kpayne@… added
Again, checkboxes is the way to go. Just wanted to defend the core, though. The behavior you're seeing is because you need two square brackets after a multiple select field name to tell php to treat the field as an array.
<select multiple="multiple" name="<?php echo $this->get_field_name('options'); ?>[]">
Can you add some details of what doesn't work, and how you expect that it should work?