Skip to content

Client-side HTML 5 validations#63

Closed
andrewhwaller wants to merge 3 commits intorubymonolith:mainfrom
andrewhwaller:client-side-html-5-validations
Closed

Client-side HTML 5 validations#63
andrewhwaller wants to merge 3 commits intorubymonolith:mainfrom
andrewhwaller:client-side-html-5-validations

Conversation

@andrewhwaller
Copy link

Spotted an issue for this (#46) and figured I'd take a crack at it!

This PR adds a Requirable concern that checks a form's underlying class for a presence validator on the relevant field (presence_validated?) and merges required: true into the field's attributes if such a validation is detected. If required: false is passed in, that value will be respected. I added the concern to Checkbox, Input, Select, and Textarea, since those are the field types that can take advantage of required. I also added some specs covering the Requirable behavior for all four.

Note: I wasn't sure if a concern was the way to go here. Putting this logic directly in Field felt possibly weird, so I just went with a concern to keep things modular/contained.

@bradgessler
Copy link
Contributor

Thanks for putting this together, @andrewhwaller! This was the inspiration for #70, which takes the same idea further — it handles required, minlength/maxlength, min/max/step, and infers them from length and numericality validators in addition to presence.

The main architectural difference is that #70 puts the validation inference on the Field (via a single prepend) rather than on each component individually, so everything flows through one place.

I'm going to close this in favor of #70, though I should note that #70 is a draft and I'm going to let it sit for a while so I can think about the approach. No immediate plans to merge. Thanks again for kicking this off!

@bradgessler bradgessler closed this Mar 1, 2026
@andrewhwaller
Copy link
Author

No problem, glad I could help!

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