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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alex.skrypnyk’s picture

Patch attached (why can't we attach files when editing the issue?)

alex.skrypnyk’s picture

Status: Active » Needs review

Please review the patch.

quicksketch’s picture

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

quicksketch’s picture

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

quicksketch’s picture

Hmm, 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).

quicksketch’s picture

Status: Needs review » Fixed

Committed this patch, seems fairly robust and should work across different browser implementations until things settle down a little bit.

fenstrat’s picture

Status: Fixed » Needs work

Interesting 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?

alex.skrypnyk’s picture

@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

quicksketch’s picture

Status: Needs work » Fixed

One hitch, wouldn't this override any disabled ("Disabled (read-only)" in Webform) setting on components when they are hidden/shown?

No, 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.

I though that the intention was to reset values on all hidden fields, and that's why I provided a patch that fixed that :)

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.

fenstrat’s picture

Thanks for the clarification on disabled components @quicksketch. All good.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

tusshar.kant’s picture

File to patch: modules/webform/js/webform.js
patching file modules/webform/js/webform.js
Hunk #1 FAILED at 153.
1 out of 1 hunk FAILED -- saving rejects to file modules/webform/js/webform.js.rej

sir I am getting this error........ plzz help me out sir..