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.
As the title says, I found that after updating to Webform 4.8, I can no longer submit a form or edit a submission that has a "select options" type that has "Allow "Other..." option" enabled and is set to be required.
Comment | File | Size | Author |
---|---|---|---|
#14 | select_or_other-html5_required-2481127-14-do-not-test.patch | 2.04 KB | DanChadwick |
#8 | select_or_other-html5_required-2481127-8.patch | 2.09 KB | DanChadwick |
Comments
Comment #1
DanChadwick CreditAttribution: DanChadwick commentedJust to follow up, webform 7.x-4.8 introduced html5 required attributes to its select components. The required attribute isn't supported for checkboxes, but for radio buttons, single-select list boxes (select elements) and multi-select list boxes, webform does use required.
Within Webform, jQuery removes the required attribute when it conditionally hides an element, and restores it when shown. I would suggest that the select_or_other jQuery do the same.
Comment #2
jmouse888 CreditAttribution: jmouse888 commentedSame issue here. However, as stated on Select (or other) module's summery page:
I'm not sure who (which module) should be responsible for fixing this. I'm running Drupal 7.36 with Webform 7.x-4.8 with NO select_or_other installed.
Comment #3
legolasboAt first glance I'd say the responsibility for this issue lies with the webform module, because the problem also exists without select_or_other installed (according to jmouse888).
I will however first try to reproduce the issue myself when i have the time to do so.
Comment #4
oriol_e9gSame problem!
How to reproduce:
Provisional solution: unchek the requiered option in the component.
Comment #5
oriol_e9gI have fixed temporally using the webform hook render.
You only need to add this code in a new module or an existing module. Replace "my_module" by the name of your module (you can also add this alter in select_or_other module to solve the problem):
Comment #6
dflitner CreditAttribution: dflitner commented#5 works for me in a separate module. Thanks oriol_e9g.
Comment #7
DanChadwick CreditAttribution: DanChadwick commentedThe issue isn't specific to webform. Select or Other is not compatible with the HTML5 required attribute. It should generate the Other textfield without it, and apply it and remove it as it shows/hides the text field.
Comment #8
DanChadwick CreditAttribution: DanChadwick commentedHere's a patch that:
I made no attempt to clean up the $ vs. jQuery inconsistencies in the js file.
Since this affects webform, a review and, if correct, RTBC and commit would be greatly appreciated.
Comment #9
legolasboThis relies on the class supplied by theme_form_element and will therefore not work in every theme. mothership for example gives the option to hide the form-item class.
Comment #10
legolasboComment #11
DanChadwick CreditAttribution: DanChadwick commentedThen that theme doesn't work now. That code is exactly the same as the existing code, just factored into a local variable.
I believe it is standard practice for module to rely on the classes they generate to make their jQuery work, no?
Comment #12
legolasboMy bad @DanChadwick,
I wasn't paying my full attention when reviewing the patch and missed the removed line of code.
You are correct in the sense that modules rely on the classes they generate, but the form-item class is not generated by select_or_other, but by Drupal core itself, which i know gets overridden quite often. You are also correct that the current implementation would not work in those cases, but in my opinion the module's JS desperately needs an overhaul. Most of the behaviour defined by the current JS implementation could be achieved by the correct use of Drupal's form states, but that's a whole other ballgame.
I think the current approach could be sufficiënt to fix the issue, but the overall JS requires a followup in the 3.x branch. However I don't currently have the time to thoroughly test the patch. If someone else reviews/tests your work and marks the issue RTBC before I get around to it, the patch will be committed.
Comment #13
DanChadwick CreditAttribution: DanChadwick commentedI agree that form #states can easily do the show/hide. I was surprised to see that required can be toggled too. https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_...
Comment #14
DanChadwick CreditAttribution: DanChadwick commentedThis seemed like a good idea, but I ran into a dead end because of #1149078: States API doesn't work with multiple select fields
Here's a patch for posterity, should the above (4 year old) issue ever get fixed and backported to D7. Not holding my breath.
What's left to do:
TL;DR: Do not review this patch. It is not currently viable due to a core bug. Review #8 instead.
Comment #15
TwoDI'm bumping this to at least "Major" since it affects a lot of forms quite seriously.
I have deployed the patch in #8 to production and it's working great both with and without JavaScript.
I suggest leaving code cleanups for a later issue since this needs to get in fast!
Great work!
Comment #16
legolasboThanks for reviewing @TwoD, I will probably commit this later tonight.
@DanChadwick, thank you for your effort so far. I've read trough #1149078: States API doesn't work with multiple select fields and there seems to be a workaround we could use to prevent hacking core. I think we should investigate using this workaround until the patch in #1149078: States API doesn't work with multiple select fields lands.
Comment #19
legolasboI've committed the patch to 2.x and rerolled + committed the patch for 3.x. Let's continue the work on implementing the states API in #2488694: Refactor to make use of form states API
Comment #20
DanChadwick CreditAttribution: DanChadwick commentedComment #21
DanChadwick CreditAttribution: DanChadwick commentedWhoops. Already related. Sorry for the noise.
Comment #22
DanChadwick CreditAttribution: DanChadwick commentedOh. Also, if you make a new release of select_or_other I can add that to the release notes. I don't want to put a version dependency into webform because it breaks for anyone who deploys without version (e.g. git without the git_deploy module).
Comment #23
legolasboI don't understand what you are trying to say here...
Comment #24
DanChadwick CreditAttribution: DanChadwick commentedRight now, this commit has not been released in a stable version. If released in 7.x-2.22, I can recommend it in the release notes for the next webform, 7.x-4.9.
I *could* add a version dependency on >=7.x-2.22 in webform.info, but I won't. If someone deploys select_or_other in a manner where core doesn't know the version number, then webform will become disabled by virtue of the dependency, breaking the site.
A common way for this to happen is someone using git push to deploy select_or_other. Unless they run the git_deploy module, select_or_other won't be packaged by the package manager, and core won't know its version.
TL;DR: Please make a new release as soon as you are comfortable doing so. I will then make a corresponding release of webform recommending that version.
Comment #25
legolasbo@DanChadwick,
7.x-2.22 will be out shortly.