Skip to content

Comments

Limit cases where "required" attribute is used on checkboxes#1194

Merged
epicfaace merged 1 commit intomasterfrom
338-checkbox-validation
Mar 6, 2019
Merged

Limit cases where "required" attribute is used on checkboxes#1194
epicfaace merged 1 commit intomasterfrom
338-checkbox-validation

Conversation

@LucianBuzzo
Copy link
Collaborator

@LucianBuzzo LucianBuzzo commented Feb 25, 2019

Fixes #338

If the "required" attribute is applied to a checkbox, then HTML5
validation will only pass if the checkbox is ticked. This is at odds
with the JSON schema definition of "required" that simply requires that
the key exists.

This PR will make it so that the "required" HTML5 attribute will only be
applied if the schema uses { const: true } or { enum: [ true ] }.

Signed-off-by: Lucian lucian.buzzo@gmail.com

Reasons for making this change

[Please describe them here]

If this is related to existing tickets, include links to them as well.

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests
    • I've updated docs if needed
    • I've run npm run cs-format on my branch to conform my code to prettier coding style
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

@epicfaace
Copy link
Member

@LucianBuzzo What about this schema?

{
      "type": "boolean",
      "oneOf": [
        {
          "const": true
        }
      ]
}

@epicfaace
Copy link
Member

@LucianBuzzo What about this schema?

{
      "type": "boolean",
      "oneOf": [
        {
          "const": true
        }
      ]
}

@LucianBuzzo Just bumping this.

@LucianBuzzo
Copy link
Collaborator Author

@epicfaace Thanks for the reminder, I'll hopefully get time to add this case this afternoon

Fixes #338

If the "required" attribute is applied to a checkbox, then HTML5
validation will only pass if the checkbox is ticked. This is at odds
with the JSON schema definition of "required" that simply requires that
the key exists.

This PR will make it so that the "required" HTML5 attribute will only be
applied if the schema uses `{ const: true }` or `{ enum: [ true ] }`.

Signed-off-by: Lucian <lucian.buzzo@gmail.com>
@LucianBuzzo LucianBuzzo force-pushed the 338-checkbox-validation branch from 2516f97 to 1c39e4b Compare March 6, 2019 09:50
@LucianBuzzo
Copy link
Collaborator Author

@epicfaace I've added additional logic for handling cases where anyOf, oneOf and allOf would require the field to be true

@epicfaace
Copy link
Member

Looks great!

@epicfaace epicfaace merged commit 2a6b830 into master Mar 6, 2019
@epicfaace epicfaace deleted the 338-checkbox-validation branch March 6, 2019 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants