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.
Hello Everyone,
I am having difficulty getting chosen to work wih webforms. The module works perfectly in the backend and with views, but I do not know what to do to make it work with webforms. Am I missing something? Thanks
Comments
Comment #1
sophiekovalevsky CreditAttribution: sophiekovalevsky commentedI'm having the same problem, not just only with webform but actually the select box doesn't show up as chosen its suposse to be.
Comment #2
elioshI solved with something like this:
Comment #3
macman911 CreditAttribution: macman911 commentedHi @eliosh, where does that code go? Thanks
Comment #4
elioshYou have to build a new custom module and put that code inside.
Just for completeness, here is my working code (with parameters for multiple options)
Comment #5
JadH CreditAttribution: JadH commented@eliosh Can you elaborate a bit about your solution?
Comment #6
elioshJadH: what kind of information do you need?
Comment #7
JadH CreditAttribution: JadH commented@eliosh
will the solution solve the issue on individual webforms or all webforms?
will I have to target each
in my webforms on its own to trigger chosen?
Comment #8
eliosh@JadH
To trigger chosen on all webform, the code is this:
If you need to customize a single webform, you have to:
Hope it helps you. If you need more info, i'm here :-)
Comment #9
rbryer CreditAttribution: rbryer commentedI'm having the same issue with Webforms. In fact the only form that seems to be correctly working is the admin page for the Chosen module itself?
I have turned off JS aggregation and can see that the chosen.js was not being added to any form other than its own admin oage.
I have created a module as described in #8 called chosen_webform and as a result I can see that the chosen.js file is being included. And the chosen.jquery.min.js library.
I have a selector set as select:visible (the default). But it is still not effecting and of the select elements on the page.
As I said the correct 'chosen' select is only displaying on the admin/config/user-interface/chosen screen. Nowhere else.
Is there anything else I am supposed to do? I have tried both the alpha4 and the dev version. Both do the same.
Comment #10
TBarina CreditAttribution: TBarina commentedSame problem here.
The strange thing is that one of my webforms behaves correctly with chosen select working properly even without code in #8.
Then I built a couple of new webforms but I cannot have them work with chosen select even if I use code in #8.
I tried and investigated everywhere but I cannot fix it.
Could anyone help?
Many thanks
Comment #11
rbryer CreditAttribution: rbryer commentedHi,
I have updated to the latest dev version, but still have issues with this widget on WebForm. By comparing a working page with a non working page I have found this issues as being with the configuration parameters. A working page has this
But a webform is missing the last section and has only this
To make this work at all I have a custom module with the following
chose_webform.module
chosen_webform.info
If I save out the non working webform page and then add the missing lines it works just fine.... any ideas how I correct this?
Comment #12
rbryer CreditAttribution: rbryer commentedOkay so I have just answered my own question!!! And I think this is actually a bug. Referring to #4 it has code to set the two missing parameters but specifies them for a field called submitted[contatti][altre_province][]. But from my code above it was apparent that as long as you have these parameters set FOR ANYTHING then the widget works. I have changed my module to...
chosen_webform.module
chosen_webform.info
Note the two parameters are set for a field called 'this_can_be_anything'. It does not matter. It would appear that a sensible default is not being applied if these are not set.
But if you set them for anything then it uses them as a default.
With the above module enabled this works for Webform fields .... and it is simply awesome!!
Comment #13
Dave ReidWith the latest beta1 and beta2 releases, I can confirm this works out of the box with Webform select elements and no additional code required.
The JS settings code referred to in #12 is a couple releases old.
Comment #14
rbryer CreditAttribution: rbryer commentedI was using 7.x-2.0-alpha4+13-dev. With this module in place and everything worked fine.
I installed and upgraded to beta2 and disabled my module and now nothing works at all. Not even the admin form for Chosen has the Chosen select boxes.
Comment #15
rbryer CreditAttribution: rbryer commentedI have had to revert back to http://ftp.drupal.org/files/projects/chosen-7.x-2.0-alpha4.zip.
Beta 2 does not work with webforms, or in fact anything else? Simply reverting back to this version with the code applied in #12 made the widget work.
Comment #16
Dave ReidI just tested Beta 2 with a clean copy of Webform. Did you read the release notes and update to the v1.1.0 version of the Chosen library?
Comment #17
Dave ReidBTW the chosen module page not having chosen is on purpose, so that in case anything went wrong with the library, you could disable it. You need to go to another page to actually test it out.
Comment #18
rbryer CreditAttribution: rbryer commentedYes I have v1.1.0 - which I initially tried to download with the drush plugin - but did not work. So I reinstalled it manually (as I think the drush plugin removed what I already had before it errored). Its now correctly installed as per the Status Page and it is working with the alpha4-dev version.
Removing chosen from the admin form is very confusing. In previous iterations it was the only form that I could actually get it to work on. But yes I did test it on other forms and it was not including the *.js or *.css files on any of them. I don't see how 'anything can go wrong with the library' other than it does not work. And you would disable it from the Modules page anyway (or drush).
Don't get me wrong, this is a fantastic feature... but its been the bane of my project from day one. At one point it worked for user=1 but no others, then not on webforms, then releases seem to break everything. I have a deadline now so can't further test and will have to go with what I have working. I will however come back to this next week.
Comment #19
Dave Reid@rbryer: That's a valid point on not seeing Chosen on the admin form. I'll consider reverting that change.
I'll leave this as needs more info because I still cannot duplicate any errors with Webform using a fresh install of Core + webform 3.x. Will need someone to test the latest module version and library version and confirm.
Comment #20
rbryer CreditAttribution: rbryer commentedI will pick this up again next week with the latest version and a real world site. I can always get this to work if I hack a page and add the correct css, js and config data. What I don't understand is the mechanism by which this are/or are not being added. Now I know what I'm looking for I can at least highlight the symptoms. As before, this is a great bit of kit and has saved me from a total UI nightmare ... but only when I can get it to work!!
Comment #21
heyyo CreditAttribution: heyyo commentedI have the same bug than rbryer, on my webform node, chosen files js/css are not loading.
But in webform edition mode it's working properly.
Which is crazy, is that on my development machine, it's working properly, the only difference is that chosen/webform settings has been sent with features/strongarm and the version of PHP (dev is 5.3 and in production PHP 5.4)
Comment #22
Dave ReidI think I have this figured out. Looks like there is a bug in Webform that removes all the #pre_render callbacks from select elements when used in Webforms, which prevents Chosen from working correctly. I'm going to file an issue against Webform, and also figure out a workaround for Chosen.
Comment #23
heyyo CreditAttribution: heyyo commentedI have found somehting interresting, I'm using "select or other" module to add an option other on my select field.
When this option is checked, chosen is working on my production website.
On my dev website it doesn't matter both are working(other... checked or unchecked).
So I suppose the weight of module chosen/webform/select_or_other could be the difference between my dev and my prod causing this bug.
I will check that tomorrow.
EDIT: I was wrong it wasn't working also on my dev website. Chosen was loaded correctly on my dev website because I had also on this webform a date component.
So it confirms your assumption on pre-render cancelled with select component, and my issue regarding webform with several pages is a duplicate of this issue. If I have a date component on the second page, Chosen is loaded correctly.
Comment #24
joelpittet#2214247: Allow Chosen to be manually toggled on Webform select components Related if not a duplicate. Thanks @Dave Reid!
Comment #25
upperholme CreditAttribution: upperholme commentedAny progress on this issue? I've just installed this module so that I can improve the UI on my webforms, and spent hours trying to get it to work at all on my site. Using the current dev version i was able to get the Chosen plugin to work on non-webform select fields, but none of my webform select fields want to play.
@Dave-Reid - what's the link for the issue you field for the Webform module? I had a quick look there but couldn't find it.
Comment #26
Vako CreditAttribution: Vako commentedI followed all the suggestions here and still unable to make Webforms work with Chosen.
In the Chosen configuration I have the following:
Minimum number of options for multi select : 5
Apply Chosen to the following elements:
select, select:visible, .chosen-select, edit-submitted-desired-area
Comment #27
Vako CreditAttribution: Vako commented...also for some reason, when I enable Chosen, the CKEditor stops working!
Comment #28
cirrus3d CreditAttribution: cirrus3d commentedHad the same problem. The only way I managed to solve this is by:
- Uninstalling this module
- Keeping the chosen library in sites/all/libraries
- adding the required files in preprocess
- executing chosen from my theme's js file (I had created a ".chosen-select" class in the webform field prior to that)
It's hardcoded but it works. Hell, you can even pull the files from a cdn (http://cdnjs.com/libraries/chosen)
Comment #29
MarcoPBazz CreditAttribution: MarcoPBazz at Bazzmann Agency commented#25 suggestion woked for me.
Comment #30
darkodev CreditAttribution: darkodev commented@MarcoPBazz I think you meant that #28 worked for you.
@cirrus3d Thanks for the tip. I was transforming views exposed filters from text into select lists and trying to apply Chosen, but it never saw them. I'm now forcing it with $(selector of your choice).chosen()
Comment #31
MarcoPBazz CreditAttribution: MarcoPBazz at Bazzmann Agency commentedOps! Sorry, of course i meant #28 :-o