Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I tried using the Multiselect widget on a custom form, without Field API, by creating a form element and setting '#type' == 'multiselect'. It works fine when not nested within a fieldset, but when you place that form element within a fieldset (with '#tree' == TRUE), selecting terms does not work (buttons do nothing when clicked).
Thanks,
Nathan
Comment | File | Size | Author |
---|---|---|---|
#17 | multiselect-nesting_issue-1230166-17.patch | 4.37 KB | thomscode |
#16 | multiselect.patch | 4.52 KB | sultancillo |
#10 | Screen Shot 2012-11-19 at 14.10.18.png | 64.01 KB | alexweber |
#8 | multiselect-nesting-issue-1230166-8.patch | 9.41 KB | kaidjohnson |
#6 | multiselect-nesting-issue-1230166-6.patch | 9.22 KB | kaidjohnson |
Comments
Comment #1
erik2e CreditAttribution: erik2e commentedSame problem here. Multiselect does not work within a fieldset.
No time to dig the problem further, but I think it's related to [ and ] added in the field name. The field name is used for CSS/JS that make the widget works, and [] might not help at all :)
A quick & (very) dirty str_replace in the module code to get rid of the [] make things works.
If someone has time to look at it, I'll be glad to help. If not, I'll post here if I can find a good solution to this.
Comment #2
asherry CreditAttribution: asherry commentedI had this problem as well, and it seemed like it really was the ID's used. I'm not sure why field_name was used for all of the ids, and in the patch I made changing the field_name didn't change any of the form submissions at all.
Hasn't yet been tested with cck fields but works for FAPI usage.
This is my first patch I hope I uploaded it right.
Comment #3
asherry CreditAttribution: asherry commentedComment #4
pelicani CreditAttribution: pelicani commentedI applied the above path and was able to alter a ecommerce product reference field to use multiselect.
Thank you for the submission asherry!
peace,
michael
Comment #5
pelicani CreditAttribution: pelicani commentedwith the above patch, when you view a cck multiselect, the ids to not get set correctly.
they are blank.
I modified the above patch with a condition to check for the #id in the element and default to the original name used in this module.
See attached.
Comment #6
kaidjohnson CreditAttribution: kaidjohnson commentedThere were some related issues to this issue, namely http://drupal.org/node/1585694 (Multiple multiselects have conflict). This patch re-rolls #5 and fixes 1585694.
Comment #7
alexweber CreditAttribution: alexweber commented@kaidjohnson thanks for the great work! Unfortunately I couldn't get the patch to apply, please re-roll against dev! Thanks!
Comment #8
kaidjohnson CreditAttribution: kaidjohnson commentedNo problem - rerolled. I also added a few comments to clarify some of the changes/updates.
Comment #9
alexweber CreditAttribution: alexweber commentedThanks @kaidjohnson, I'll take a look tomorrow morning and hopefully commit it :)
Comment #10
alexweber CreditAttribution: alexweber commented@kaidjohnson, the patch applies fine but it introduces some weird behavior: the multiselect widget is now automatically populated with all options and none of them can be removed.
Comment #11
kaidjohnson CreditAttribution: kaidjohnson commentedYes, I do see that now. It works in a multiple, nested instance, but not in a singular instance. After playing around with a few things, I have noticed a few issues come up with recent updates that are related to the issue you are seeing.
1) The new way in including the css and js as #attached seems to work for the field api but not for the form api. My programmatically created multiselect fields fail to include the css and js when using #attached, but the fields I created through the field api look and work as expected with this method. Reverting back to the previous drupal_add_css/js works for both instances. This issue began with commit 8eef5b6.
2) The addition of the #after_build workaround causes the code to completely bypass theme_multiselect. Try commenting out the #after_build on line 127 of multiselect.module and try your multiselect field again (with the proposed patch I included above) and you should see it working as expected. To further test this, add a die() to theme_multiselect and re-enable the #after_build. Neither of my test fields killed the page - comment out #after_build, and boom, dead as expected. This issue began with commit 8e8bedc. I recommend investigating an alternate solution for this patch to maintain the current render flow.
At the present time, I'm hesitant to work on re-rolling my patch above as I expect the base code will need a revision to correct the reversions mentioned.
-- UPDATE --
The css/js issue is because the form api does not appear to call multiselect_field_widget_form(), which also explains why my multiple, nested test fields aren't affected by the issue you've documented above - the form api is using theme_multiselect; the field api is using #after_build. Hope that helps...
-- END UPDATE --
Comment #12
alexweber CreditAttribution: alexweber commentedThanks @kaidjohnson for taking the time to look into this. I'll take some time over the next few days to figure out the two issues you pointed out and I'll post back here soon :)
Comment #13
alexweber CreditAttribution: alexweber commentedUnfortunately I just haven't had the time. Patches welcome as usual, thanks!
Comment #14
johnvTry using hook_element_info
Comment #15
mitchalbert CreditAttribution: mitchalbert commentedany news on this issue? using multiselect 7.x-1.10
Comment #16
sultancillo CreditAttribution: sultancillo as a volunteer commentedThis patch solves the multiple multiselects for me (with field api on a "Modify entity values" screen from Views Bulk Operations) i don't have a good test case for FAPI which uses theme_multiselect
Comment #17
thomscode CreditAttribution: thomscode at Pacific Northwest National Laboratory commentedRe-rolling this patch to work with composer.