Skip to content

Infer HTML5 validation attributes from ActiveRecord validators#70

Draft
bradgessler wants to merge 1 commit intomainfrom
html5-validation-attributes
Draft

Infer HTML5 validation attributes from ActiveRecord validators#70
bradgessler wants to merge 1 commit intomainfrom
html5-validation-attributes

Conversation

@bradgessler
Copy link
Contributor

Summary

  • Adds HTML5::ValidationAttributes class that reads ActiveRecord validators and produces corresponding HTML5 attributes (required, minlength, maxlength, min, max, step)
  • A thin Validations module prepends onto Field to merge these attributes into input, checkbox, textarea, select, and radio calls
  • User kwargs always win over inferred attributes
  • Conditional validators (if:, unless:, on:) are skipped since they can't be evaluated at render time
  • Forms can opt out via def novalidate = true

Test plan

  • 26 new specs covering ValidationAttributes, Field method overrides, convenience methods, novalidate
  • All 153 specs pass (127 existing + 26 new)

Adds HTML5::ValidationAttributes class that reads ActiveRecord validators
and produces corresponding HTML5 attributes (required, minlength, maxlength,
min, max, step). A thin Validations module prepends onto Field to merge
these attributes into input, checkbox, textarea, select, and radio calls.

User kwargs always win over inferred attributes. Conditional validators
(if:, unless:, on:) are skipped since they can't be evaluated at render time.

Forms can opt out via `def novalidate = true`, which suppresses attribute
injection and adds the novalidate attribute to the <form> tag.
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.

1 participant