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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

erik2e’s picture

Same 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.

asherry’s picture

I 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.

asherry’s picture

Assigned: Unassigned » asherry
Status: Active » Needs review
pelicani’s picture

I 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

pelicani’s picture

with 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.

kaidjohnson’s picture

There 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.

alexweber’s picture

Status: Needs review » Needs work

@kaidjohnson thanks for the great work! Unfortunately I couldn't get the patch to apply, please re-roll against dev! Thanks!

kaidjohnson’s picture

No problem - rerolled. I also added a few comments to clarify some of the changes/updates.

alexweber’s picture

Thanks @kaidjohnson, I'll take a look tomorrow morning and hopefully commit it :)

alexweber’s picture

@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.

kaidjohnson’s picture

Yes, 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 --

alexweber’s picture

Assigned: asherry » Unassigned

Thanks @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 :)

alexweber’s picture

Unfortunately I just haven't had the time. Patches welcome as usual, thanks!

johnv’s picture

mitchalbert’s picture

Issue summary: View changes

any news on this issue? using multiselect 7.x-1.10

sultancillo’s picture

FileSize
4.52 KB

This 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

thomscode’s picture

Re-rolling this patch to work with composer.