Client-side HTML 5 validations #63
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Spotted an issue for this (#46) and figured I'd take a crack at it!
This PR adds a
Requirableconcern that checks a form's underlying class for a presence validator on the relevant field (presence_validated?) and mergesrequired: trueinto the field's attributes if such a validation is detected. Ifrequired: falseis passed in, that value will be respected. I added the concern toCheckbox,Input,Select, andTextarea, since those are the field types that can take advantage ofrequired. I also added some specs covering theRequirablebehavior for all four.Note: I wasn't sure if a concern was the way to go here. Putting this logic directly in
Fieldfelt possibly weird, so I just went with a concern to keep things modular/contained.