Skip to content

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

Closed
@TimCorey

Description

@TimCorey

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.

Activity

TimCorey

TimCorey commented on Jul 13, 2016

@TimCorey
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

Anthropic commented on Jul 17, 2016

@Anthropic
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

Anthropic commented on Jul 17, 2016

@Anthropic
Member

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

Anthropic

Anthropic commented on Apr 15, 2017

@Anthropic
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Anthropic@TimCorey

        Issue actions

          Validating a boolean (checkbox) that is required to be true · Issue #736 · json-schema-form/angular-schema-form