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.
When non-text conditional components, such as checkboxes or radios, are triggered to be hidden, they values get removed and they can not trigger further children conditionals.
Attached patch resolves this issue.
Comment | File | Size | Author |
---|---|---|---|
#5 | webform_conditional_hidden_value.patch | 692 bytes | quicksketch |
#1 | webform-nontext_conditionals_deleted-1.patch | 1.34 KB | alex.skrypnyk |
Comments
Comment #1
alex.skrypnykPatch attached (why can't we attach files when editing the issue?)
Comment #2
alex.skrypnykPlease review the patch.
Comment #3
quicksketchThere was another issue where I was discussing this topic but I can't locate it... weird.
Marked a few things duplicate:
#1648186: File upload component submit button input value attirbute empty when conditionally hidden
#1677256: Multiple Conditions fails when one condtion is nested
In short I think the attempt to set input values to an empty string was a flawed approach. The reason for it was to prevent HTML5 validation errors from preventing form submission. For example having a hidden e-mail field contain an invalid e-mail address would prevent all submission of the form by HTML5 browsers. A validation error would be shown next to the field, but since the field is hidden, the entire form just appears to silently fail.
Rather than removing the value of hidden fields, we should respond to the HTML5 event for "invalid" and suppress the failure if the field is hidden.
Comment #4
quicksketchAh here's the related issue: #1630606: Conditions inside a fieldset not working. I explain the same situation over there, but the patch solves a separate problem in addition to this one.
Comment #5
quicksketchHmm, apparently my idea to capture the "invalid" event doesn't seem to work. Though the W3C spec says that the event is cancelable, if you try to use e.preventDefault() (as suggested in http://stackoverflow.com/questions/3090369/disable-validation-of-html5-f...), it just suppresses the validation message, but the form still doesn't submit.
Reading through http://code.google.com/p/chromium/issues/detail?id=45640, someone made the useful suggestion of setting the "disabled" attribute will cause validation to be skipped (since the element value is not included in POST either).
Comment #6
quicksketchCommitted this patch, seems fairly robust and should work across different browser implementations until things settle down a little bit.
Comment #7
fenstratInteresting approach, seems to work well.
One hitch, wouldn't this override any disabled ("Disabled (read-only)" in Webform) setting on components when they are hidden/shown?
Comment #8
alex.skrypnyk@quicksketch
I though that the intention was to reset values on all hidden fields, and that's why I provided a patch that fixed that :)
But now, knowing that you had other intentions, my patch brings totally other feature request, which I lodged here http://drupal.org/node/1702274
Comment #9
quicksketchNo, because Webform doesn't actual disable "disabled" components, it actually uses the "readonly" attribute, otherwise they wouldn't get saved to the database at all.
The only real intention was to prevent validation errors. My logic was that empty fields don't cause validation errors (which was flawed), so I thought that was the easiest approach. In any case Webform discards hidden elements now in the submit handler, so it doesn't matter if it's empty or not. The #disabled attribute just accomplishes it in two ways now (both client-side and server-side). So seems like a win. :)
Thanks to both of you for testing and your suggestions!! Moving this back to fixed, I think we just cross-posted.
Comment #10
fenstratThanks for the clarification on disabled components @quicksketch. All good.
Comment #12
tusshar.kant CreditAttribution: tusshar.kant commentedsir I am getting this error........ plzz help me out sir..