The required states need to be set on the element, not the wrapper.

This affects the Save preferences and Accept all categories button label for the the Categories consent method, Agree button label, Cookie policy button label, Disagree button label and More info label.

The proper syntax can be seen in https://api.drupal.org/comment/62866#comment-62866

Comments

svenryen created an issue. See original summary.

svenryen’s picture

Update: I did some testing and the code works, but when we set required using #states, we still need to validate the input on form submit to check that the required fields are filled out.

In D8, there's client side validation of the form based on the required states, which stops the form from submitting if the required fields are not filled out.

reszli’s picture

StatusFileSize
new70.85 KB

thank you fields are required even if thank you banner is not enabled
the UX could be improved by using #states for the 'required' attribute of these elements

form errors

svenryen’s picture

Addressing the issue that @reszli pointed out, here are patches for 7.x and 8.x.

Test notes:
- Verify that the remaining fields in the "Thank you banner" pane are hidden when "Enable Thank You banner" is unchecked.
- Verify that the remaining fields in the "Thank you banner" pane appear when "Enable Thank You banner" is checked.
- Verify that you get errors on empty fields in the 3 Thank you fields.

neslee canil pinto’s picture

Status: Needs review » Needs work

8.x branch patch needs a reroll against latest dev.

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4542  100  4542    0     0   2711      0  0:00:01  0:00:01 --:--:--  2711
error: patch failed: src/Form/EuCookieComplianceConfigForm.php:582
error: src/Form/EuCookieComplianceConfigForm.php: patch does not apply
neslee canil pinto’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new2.28 KB

Rerolled patch and added semicolon at the end of js function

neslee canil pinto’s picture

StatusFileSize
new4.23 KB

  • Neslee Canil Pinto committed ace4d52 on 8.x-1.x
    Issue #3070778 by svenryen, Neslee Canil Pinto, reszli: Required #states...
neslee canil pinto’s picture

Status: Needs review » Fixed

Committed to dev branch. Thank you.

neslee canil pinto’s picture

Assigned: neslee canil pinto » Unassigned

  • svenryen committed 062e4fb on 7.x-2.x
    Merge branch '7.x-1.x' into 7.x-2.x
    
    * 7.x-1.x:
      Issue #3175031 by...
  • Neslee Canil Pinto committed 6ece5b5 on 7.x-2.x authored by svenryen
    Issue #3070778 by svenryen, reszli: Required #states are not working
    

Status: Fixed » Closed (fixed)

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