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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DanChadwick created an issue. See original summary.

jrockowitz’s picture

The attached webform replicates this issue.

  • a92cb78 committed on 3089074-likert-states-required
    Issue #3089074 by jrockowitz: Required likert not themed or validated if...
jrockowitz’s picture

Status: Active » Needs review
FileSize
9.93 KB
DanChadwick’s picture

Status: Needs review » Needs work

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

DanChadwick’s picture

Status: Needs work » Needs review
FileSize
2.5 KB

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

  • ec5cd30 committed on 3089074-likert-states-required
    Issue #3089074 by jrockowitz: Required likert not themed or validated if...
jrockowitz’s picture

DanChadwick’s picture

Status: Needs review » Reviewed & tested by the community

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

jrockowitz’s picture

If we run into third instance of this type of problem we should delegate this to the webform element plugin.

jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

  • jrockowitz authored ae5482b on 8.x-5.x
    Issue #3089074 by jrockowitz, DanChadwick: Required likert not themed or...
  • jrockowitz authored cde39f0 on 8.x-5.x
    Issue #3089074 by jrockowitz, DanChadwick: Required likert not themed or...
DanChadwick’s picture

Many thanks, as usual, for your super great support! Much appreciated.

DanChadwick’s picture

Status: Fixed » Needs work
FileSize
1.15 KB

I noticed in a code review that the code processes the conditional likert as required always, even if the likert is optional. Patch attached.

  • ef15e1d committed on 8.x-5.x
    Issue #3089074 by jrockowitz, DanChadwick: Required likert not themed or...
jrockowitz’s picture

Status: Needs work » Fixed

Good catch!

Status: Fixed » Closed (fixed)

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