After adding #254728: Conditional fields, some conditional field values may be saved even if they were supposed to be skipped. To reproduce:
- Make a 2 page form with an element on the second page being dependent on a first page component.
- Enter the dependent value on page 1, click next.
- Set a value on page 2, then click previous.
- Enter a different value on page 1 that should hide the field on page 2. Click next.
- The form is submitted (meaning page 2 was skipped), but the value entered on page 2 the first time will still be saved.
We need to have some kind of cleansing of values once the submission is completed. I actually really like it maintaining values even if they're not necessary while filling out the form, in case a user changes their mind a few times about the value of a conditional field.
Comments
Comment #1
jmrivero commentedMay be with a validation that checks for a previous value in the current form and then if it changes on submit, reset the previous value or always clear the form state of the current page on load.
Comment #2
quicksketchYour issue over in #932250: Previous page button should reset previous submited data (marked duplicate) brought up a slightly different problem also. If you have 2 conditional components on page 1, you go to page 2 and set a value, then return to page 1 and change your options, the values set on page 2 may affect OTHER fields on page 3 and make them show up too. So we need to not only clear out inapplicable values on save, but as soon as you progress past the page containing the conditional fields.
Comment #3
jmrivero commentedThe worst case is when all the fieldsets are mandatory, if you select only one option on page 3 and leave empty the other fieldset it wont let you go fordward. Also this issue causes that you end with up to one fieldset in page 3 per option you have in page 1 if you repeat the steps for each option in page 1.
I think that if you always clear the childrens of the current conditional field that should do it.
Comment #4
jmrivero commentedI think i have a clue on this issue, add this to webform.module on line 1776:
It shows that some forms are been saved to the storage even if there is no value selected for it, that is fine for the next page button but not for the previous page button, which is saving it.
My two cents.
Comment #5
jmrivero commentedMaybe this can provide a start to fix this issue.
Add this code to webform.module in line 1818.
Comment #6
quicksketchAn excellent recap of this problem has been marked duplicate in #1322202: Values in fields hidden by Conditional rules is saved in submissions..
Comment #7
quicksketchThis is being solved in #1215456: Multiple and same-page conditional rules.
Comment #8
quicksketch