Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Steps to reproduce the error:
- Create a new boolean field on a content type, and mark it as required.
- Create a new node of that content type and do not set the boolean field; the form passes validation, rather than saying 'x is required'.
Comments
Comment #1
yoroy CreditAttribution: yoroy commentedConfirmed on D8. The 'required' is not honored when submitting the form for a new node.
Comment #2
attiks CreditAttribution: attiks commentedsubscribing for #1239910: META: tracking other issues about validation
Comment #3
seddonym CreditAttribution: seddonym commentedShould this have been moved to version 8? I believe it's also a problem for version 7, maybe make a new issue for 8?
Comment #4
bigkevmcd CreditAttribution: bigkevmcd commentedWhat would you expect it to do?
As a Boolean field can only be on or off, would you expect making it required to require it to be on?
If so, why bother with it at all?
Are you attempting to make a "Accepted terms?" type form? If so, then it's not the field that's required, but you require that the user submit the value as True?
Comment #5
attiks CreditAttribution: attiks commented@bigkevmcd if you make a checkbox required, it means it has to be checked according to the specs. So if we allow users to mark it as required it means we need to validate it as well. html5 has the same behavior, if it's required and not checked you get a validation error and you can't submit the form.
Why bother: because some countries don't allow you to subscribe people automatically to newsletters, so an 'allowed' work-around is to display a checkbox and make it required.
Comment #6
bigkevmcd CreditAttribution: bigkevmcd commentedWhich countries allow you to do this? Certainly it wouldn't be allowed under EU 2002/58/EC (or the 2003 amendment), the user is required to have explicitly opted-in to a newsletter.
Comment #7
attiks CreditAttribution: attiks commentedIt was just one example, your example in #4 where people need to explicitly check 'accept terms' is another one. Probably there might be some other use cases.
My other point remains: if we allow users to mark it as required it means we need to validate it as well.
Comment #8
seddonym CreditAttribution: seddonym commentedResponding to #4, one use case is if we want to display the boolean as radio buttons, without an initial value (so users have to choose).
Anyway all this can be achieved using the List (text) field but sometimes it seemed a boolean field was more appropriate.
I'm also moving this back to version 7 (for which it is still an issue), but I've created a ticket for version 8 too.
Comment #9
tim.plunkettKeep it in the same issue.
Comment #10
droplet CreditAttribution: droplet commentedcan't reproduce with latest -dev. seems it's fixed.
Comment #11
dwwStill a bug in 7.x, moving back.
Comment #12
droplet CreditAttribution: droplet commented#811542: Regression: Required radios throw illegal choice error when none selected
Comment #13
junkbox CreditAttribution: junkbox commentedresponding to #5 and #7...yeah at first it threw me into a logic loop...but you're right. 'Not Required' means false is submitted and therefore the field while 'not required' is inherently binary and works itself out, because it always gives a value. Forcing a tick also has it's use cases, 'tick here if you're over 18 and agree to the terms', so it's really win win. I think it's great to have the option for requirement and the logic is sound. Maybe a tool tip to stop dummies like me from thinking it's broke (assuming it's not) and freaking out about validation errors...then googling...then running across this post, might be a good thing.