Skip to content

Validating a boolean (checkbox) that is required to be true #736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TimCorey opened this issue Jul 13, 2016 · 4 comments
Closed

Validating a boolean (checkbox) that is required to be true #736

TimCorey opened this issue Jul 13, 2016 · 4 comments

Comments

@TimCorey
Copy link

I've included a boolean field in my schema form demo. I would like it to be a "Terms and Conditions" checkbox, where the user is required to check the box before continuing. Making the field a required field does nothing, I assume because false is a value. In order to gain the functionality to require the checkbox to be checked, I added a function to the $validators object. This worked in that the form cannot be processed without the checkbox being checked. However, the user is given no message below the checkbox itself, even though I included a validation message.

Have I missed something? I'd love for the checkbox to get the same validation cues as input fields.

@TimCorey
Copy link
Author

After further testing, it seems as though the validation message will fire if I check the box and then uncheck it. It will also show the proper error. This still doesn't happen on submit. That is where I need it to happen.

Just for further clarity, I'm not giving the checkbox an initial value, which means it defaults to false (which is what I want).

@Anthropic
Copy link
Member

@TimCorey have you tried using validateOnRender, that would show the error immediately? Failing that can you hide the submit buttons until the checkbox is checked?

@Anthropic
Copy link
Member

I do see the issue though and agree it is a bug worth addressing.

@Anthropic
Copy link
Member

@TimCorey I am closing this because technically the attribute you want is { const: true } as part of the schema, this isn't supported in tv4, but making ajv or djv available to validate with is already covered in other issues.

Const is part of json-schema v6 json-schema-org/json-schema-spec#58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants