Apparently there are no server side validation of reqired grid component questions on a webform with page breaks.
There are at least two ways to circumvent the HTML5 validation without the user ever tampering with the code.
1) Javascript listeners bound to the submit button can in some instances cause an involuntary jump to the next page (https://www.drupal.org/node/2661154 and https://www.drupal.org/node/2628962).
2) If you edit your webform (add a new component) while it is viewed by a user, and the user revisit the page (by hitting the url again, not reloading with F5), the user is sent to the next page skipping the required fields.
As far as my testing goes, this is only a problem with grids. If you add a required 'Select Options' component, for example, method one above triggers a form_set_error(), and method two brings up the HTML5 validation preventing the user from going further.
Comments
Comment #2
nicolaj.knudsen@gmail.com commentedI think i've solved the issue, will try to commit a patch shortly.
One more way to reproduce the bug (i.e. skip HTML5 validation):
- View a multipage webform, fill out the first page correctly.
- Go to the next page containing only (required) grid components.
- Go back to the previous page
- Go to the second one more time.
- Reload the page and confirm the resubmit promt.
You will be sent to the third page skipping the required grids.
Comment #3
nicolaj.knudsen@gmail.com commentedComment #4
nicolaj.knudsen@gmail.com commentedI'm changing the priority to major, since this bug does cause loss of user data.
Comment #5
nicolaj.knudsen@gmail.com commentedComment #7
nicolaj.knudsen@gmail.com commentedComment #8
nicolaj.knudsen@gmail.com commentedComment #9
danchadwick commentedThere is a bug, but specifically the server only validates that the grid contains at least one answer, rather than all the questions are answered.
The correct fix is to implement webform_validate_grid(). See webform_validate_date() as an example.
To reproduce this for testing purposes, you can comment out the following lines from webform_expand_grid:
Comment #11
danchadwick commentedCommitted to 7.x-4.x.
Comment #12
danchadwick commentedComment #13
andreavr commentedHi,
I've been testing a webform using Grid components and general Textfields nested underneath. On updating from 7.x-4.13 -> 7.x-4.14 now my non-required Textfields are treated as required and I'm thinking it's related to this update?
Question 1: Grid required
---Comments: Textfield Not-required
Is this what it's meant to do? If so I'll have to take my Textfield out of the Grid but thought that was the way to format things nicely...
Cheers
Andrea
Comment #14
danchadwick commentedI agree. Nested components within a required grid should not be required unless they themselves are required. Also, if the entire grid is set as being an error, then all nested components are shown in error highlighting, even if they are not required. Consequently, we have to set each individual question as an error.
Comment #16
danchadwick commentedCommitted to 7.x-4.x.
Comment #17
danchadwick commentedBoth patches need up-port to D8.
Comment #18
fenstratClosing to clear out the old Webform 8.x-4.x branch. See #2827845: [roadmap] YAML Form 8.x-1.x to Webform 8.x-5.x.