{"id":13880462,"url":"https://github.com/amatsuda/html5_validators","last_synced_at":"2025-10-08T17:25:18.247Z","repository":{"id":1500868,"uuid":"1754631","full_name":"amatsuda/html5_validators","owner":"amatsuda","description":"A gem/plugin for Rails 3, Rails 4, Rails 5, and Rails 6 that enables client-side validation using ActiveModel + HTML5 Form Validation","archived":false,"fork":false,"pushed_at":"2025-04-29T11:02:13.000Z","size":377,"stargazers_count":304,"open_issues_count":10,"forks_count":37,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-13T23:53:06.950Z","etag":null,"topics":["activemodel","activerecord","html5","rails","ruby","validations"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amatsuda.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2011-05-16T10:02:00.000Z","updated_at":"2025-04-29T11:02:17.000Z","dependencies_parsed_at":"2023-02-12T15:17:07.693Z","dependency_job_id":null,"html_url":"https://github.com/amatsuda/html5_validators","commit_stats":{"total_commits":264,"total_committers":10,"mean_commits":26.4,"dds":0.0757575757575758,"last_synced_commit":"de9fc8e06bd1d58a4d5a4348b5b8691fb1476efd"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amatsuda%2Fhtml5_validators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amatsuda%2Fhtml5_validators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amatsuda%2Fhtml5_validators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amatsuda%2Fhtml5_validators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amatsuda","download_url":"https://codeload.github.com/amatsuda/html5_validators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535792,"owners_count":22087397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activemodel","activerecord","html5","rails","ruby","validations"],"created_at":"2024-08-06T08:03:03.294Z","updated_at":"2025-10-08T17:25:18.158Z","avatar_url":"https://github.com/amatsuda.png","language":"Ruby","readme":"# HTML5Validators\n\nAutomatic client-side validation using HTML5 Form Validation\n\n## What is this?\n\nhtml5_validators is a gem/plugin for Rails 3+ that enables automatic client-side\nvalidation using ActiveModel + HTML5. Once you bundle this gem on your app,\nthe gem will automatically translate your model validation code into HTML5\nvalidation attributes on every `form_for` invocation unless you explicitly\ncancel it.\n\n## Features\n\n### PresenceValidator =\u003e required\n\n* Model\n```ruby\nclass User\n  include ActiveModel::Validations\n  validates_presence_of :name\nend\n```\n\n* View\n```erb\n\u003c%= f.text_field :name %\u003e\n```\nother `text_field`ish helpers, `text_area`, `radio_button`, and `check_box` are also available\n\n* HTML\n```html\n\u003cinput id=\"user_name\" name=\"user[name]\" required=\"required\" type=\"text\" /\u003e\n```\n\n* SPEC\n\nhttp://dev.w3.org/html5/spec/Overview.html#attr-input-required\n\n![PresenceValidator](https://raw.githubusercontent.com/amatsuda/html5_validators/0928dc13fdd1a7746deed9a9cf7e865e13039df8/assets/presence.png)\n\n### LengthValidator =\u003e maxlength\n\n* Model\n```ruby\nclass User\n  include ActiveModel::Validations\n  validates_length_of :name, maximum: 10\nend\n```\n\n* View\n```erb\n\u003c%= f.text_field :name %\u003e\n```\n`text_area` is also available\n\n* HTML\n```html\n\u003cinput id=\"user_name\" maxlength=\"10\" name=\"user[name]\" size=\"10\" type=\"text\" /\u003e\n```\n\n* SPEC\n\nhttp://dev.w3.org/html5/spec/Overview.html#attr-input-maxlength\n\n### NumericalityValidator =\u003e max, min\n\n* Model\n```ruby\nclass User\n  include ActiveModel::Validations\n  validates_numericality_of :age, greater_than_or_equal_to: 20\nend\n```\n\n* View (be sure to use number_field)\n```erb\n\u003c%= f.number_field :age %\u003e\n```\n\n* HTML\n```html\n\u003cinput id=\"user_age\" min=\"20\" name=\"user[age]\" size=\"30\" type=\"number\" /\u003e\n```\n\n* SPEC\n\nhttp://dev.w3.org/html5/spec/Overview.html#attr-input-max\nhttp://dev.w3.org/html5/spec/Overview.html#attr-input-min\n\n![NumericalityValidator](https://raw.githubusercontent.com/amatsuda/html5_validators/0928dc13fdd1a7746deed9a9cf7e865e13039df8/assets/numericality.png)\n\n### And more (coming soon...?)\n:construction:\n\n## Disabling automatic client-side validation\n\nThere are four ways to cancel the automatic HTML5 validation.\n\n### 1. Per form (via form_for option)\n\nSet `auto_html5_validation: false` to `form_for` parameter.\n\n* View\n```erb\n\u003c%= form_for @user, auto_html5_validation: false do |f| %\u003e\n  ...\n\u003c% end %\u003e\n```\n\n### 2. Per model instance (via model attribute)\n\nSet `auto_html5_validation = false` attribute to ActiveModelish object.\n\n* Controller\n```ruby\n@user = User.new auto_html5_validation: false\n```\n\n* View\n```erb\n\u003c%= form_for @user do |f| %\u003e\n  ...\n\u003c% end %\u003e\n```\n\n### 3. Per model class (via model class attribute)\n\nSet `auto_html5_validation = false` to ActiveModelish class' class variable.\nThis configuration will never be propagated to inherited children classes.\n\n* Model\n```ruby\nclass User \u003c ActiveRecord::Base\n  self.auto_html5_validation = false\nend\n```\n\n* Controller\n```ruby\n@user = User.new\n```\n\n* View\n```erb\n\u003c%= form_for @user do |f| %\u003e\n  ...\n\u003c% end %\u003e\n```\n\n### 4. Globally (via HTML5Validators module configuration)\n\nSet `config.enabled = false` to Html5Validators module.\nMaybe you want to put this in your test_helper, or add a controller filter as\nfollows for development mode.\n\n* Controller\n```ruby\n# an example filter that disables the validator if the request has {h5v: 'disable'} params\naround_action do |controller, block|\n  h5v_enabled_was = Html5Validators.enabled\n  Html5Validators.enabled = false if params[:h5v] == 'disable'\n  block.call\n  Html5Validators.enabled = h5v_enabled_was\nend\n```\n\n## Supported versions\n\n* Ruby 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3 (trunk)\n\n* Rails 3.2.x, 4.0.x, 4.1, 4.2, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, 7.1 (edge)\n\n* HTML5 compatible browsers\n\n\n## Installation\n\nPut this line into your Gemfile:\n```ruby\ngem 'html5_validators'\n```\n\nThen bundle:\n```\n% bundle\n```\n\n## Notes\n\nWhen accessed by an HTML5 incompatible legacy browser, these extra attributes\nwill just be ignored.\n\n## Todo\n\n* more validations\n\n\n## Copyright\n\nCopyright (c) 2011 Akira Matsuda. See MIT-LICENSE for further details.\n","funding_links":[],"categories":["Ruby","Filtering and Validation"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famatsuda%2Fhtml5_validators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famatsuda%2Fhtml5_validators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famatsuda%2Fhtml5_validators/lists"}