A likert element with the required attribute which is conditionally shown is not displayed with the red asterisk "required" indicator, and if the likert value is missing, does display a validation error.
To reproduce, create a simple likert with a couple of question and answers. Specify required for validation. Observe that it works as expected. Create a conditional which controls the display of the likert. Now observe that even when the likert is shown, it does not behave as if it were required.
I believe this is because when #states controls the display of the likert, the actual #required state is moved to #_required. However, the likert element does not support #_required when it build the compound element.
Comment | File | Size | Author |
---|---|---|---|
#14 | webform-required_likert-3089074-14.patch | 1.15 KB | DanChadwick |
#8 | 3089074-7.patch | 10.31 KB | jrockowitz |
| |||
#6 | webform-likert_validation-3089074-6.patch | 2.5 KB | DanChadwick |
#4 | 3089074-3.patch | 9.93 KB | jrockowitz |
| |||
#2 | webform.webform.issue_3089074.yml | 4.78 KB | jrockowitz |
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe attached webform replicates this issue.
Comment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #5
DanChadwick CreditAttribution: DanChadwick commentedThanks for this patch. Unfortunately, src/WebformSubmissionConditionsValidator::validateFormElement() hard-codes the test for 'webform-likert'. I sub-class webform's likert element, so testing #type for 'webform-likert' doesn't work. Patch forthcoming.
Comment #6
DanChadwick CreditAttribution: DanChadwick commentedThe attached patch changes the validation test for likerts from '#type' to instanceof, allowing subclasses of likerts to receive proper conditional validation for required. This patch applies to the above issue branch from #3.
Comment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #9
DanChadwick CreditAttribution: DanChadwick commentedWhile I'm marking this as RTBC*, really this sort of logic should be delegated to the element plugin. This would make such logic less brittle. You can see similar logic in WebformSubmissionExportImportImporter, for example. This is a larger architectural issue, which if desired could be addressed in a separate feature request.
* Technically I contributed to this patch so I shouldn't mark it RTBC, but I doubt there are any other users subclassing the likert element who could test this.
Comment #10
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedIf we run into third instance of this type of problem we should delegate this to the webform element plugin.
Comment #11
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #13
DanChadwick CreditAttribution: DanChadwick commentedMany thanks, as usual, for your super great support! Much appreciated.
Comment #14
DanChadwick CreditAttribution: DanChadwick commentedI noticed in a code review that the code processes the conditional likert as required always, even if the likert is optional. Patch attached.
Comment #16
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedGood catch!