Hi Webform Development Team,
First of all I want to say this is an excellent module and I've switched back to using it from Entity Forms after some recent bug fixes. I tried searching for this issue/bug first and was unsuccessful in finding a pre-existing report of it. With that said, if I missed it please feel free to give me a slap on the wrist.
Issue Experienced:
I've got a drop-down field that has a condition where if the user selects a specific value in another drop-down, above it in the form, it will automatically be set to a specific value (the value it is set to is one of the values available normally). The actual conditional action seems to work fine, the value gets set as it should be. However, when I go to submit the form, the drop-down field, that gets its value automatically set, is highlighted in red and an error message is displayed stating the field is required.
I've also noticed that the field getting highlighted in red and an error message displayed appears to be the old method of stating a field must be filled out? In the latest versions of webform it appears a new method with a text bubble right below the affected field(s) is displayed instead. Just a thought... Idk if this is still working as it should or not.
Please let me know if there is any other information I can possibly provide you on this or if my description is terrible and thank you in advance for your assistance.
- Kyle
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | webform-condtiional_validation-2517090-9.patch | 17.24 KB | danchadwick |
| #4 | webform-set_validation-2517090-4.patch | 833 bytes | danchadwick |
Comments
Comment #1
decyphex commentedComment #2
danchadwick commentedReproduced.
The "bubbles" are provided by the html5 required attribute. The webform jQuery adds/removes this when fields are shown/hidden.
The non-bubble validation message is being generated by the server validation code. This code runs in addition to the jQuery because javascript may be disabled in the browser or the submission may be being made by an attacker. This code apparently does not see the set value properly. I did note that the value is stored in the database if automatic draft saving is enabled. Curious.
Comment #3
decyphex commentedI did try to enable the automatic draft feature but since I don't have any page breaks, it did not resolve the issue. What I found interesting though and I'm guessing its due to what you said about the value getting stored when this option is enabled, is that on a second attempt to submit, after the first required field message, the form would submit.
I've decided, for the time being, to just make the field not-required and added a description below it stating that an option does need to be selected. Do you think this is something that can be fixed in the nearer future or is it more of a large re-write type deal?
Either way, thank you for the quick reply and I'm glad you were able to reproduce it quickly.
Comment #4
danchadwick commentedHere's what's happening. When the jQuery disables the select list (in order to prevent changes, since I'm pretty sure readonly isn't supported), it causes the data set by the jQuery to not be sent to the server. The server also executes the conditionals, but the validation code looks at the data from the browser, not the conditionals.
The tricky bit is that while I could easily look at the conditionally-set values in Webform's validation, there might be other validation set by other modules or via hook_form_alter(). If I just set the value in the element before calling the validation routines, it may not be in the format expected by the form element because webform normalizes how data is stored into its standard format.
You can try this patch, but without substantial testing for regressions, it isn't ready to be committed.
Also, if someone could work on the issue in the queue about tests not passing (unrelated to this), then that would unblock this issue. I certainly want to make sure tests pass.
Comment #5
danchadwick commentedFixed but unable to upload the patch or commit the fix due to limited internet access. Stay tuned.
Do not use patch 4. It's not the right solution.
Comment #7
decyphex commentedThank you DanChadwick. Will await your updated patch and I'm glad I hadn't gotten the chance to try the patch in #4 yet.
Comment #8
danchadwick commentedPatch 4 may work for you in the interim. Test thoroughly.
Comment #9
danchadwick commentedA rather large patch.
Initially my thought was just to disable validation when a value is set by a conditional. However, this may lead to integrity problems. For example, you might have unique validation on, allowing only one person to have the value set by the conditional. So this requires that Webform be able to put a value back into the form and form_state. This is complicated because every form element is different in how values are represented.
So, this patch:
_webform_action_set_COMPONENT(). Except for markup components. More below on that._webform_client_form_validate(), if the component is being set by a conditional, then the component hook is called to set the $form and $form_state. Unfortunately webform_component_invoke() can't be used for this because it doesn't support reference arguments, and the hooks need to set both the $form and $form_state.template_preprocess_webform_element()was fixed, where if a #wrapper_attribute is set and it isn't the class, the component's classes are omitted from the output.Committed to 7.x-4.x and, astonishingly, 8.x.