Git Product home page Git Product logo

html5_validators's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

html5_validators's Issues

Should support non ActiveRecord::Base classes

The class method auto_html5_validation is added to ActiveRecord::Base, when imho it should be in ActiveModel::Model. This would allow auto_html5_validation to work with objects that just include ActiveModel::Model. (Which is often done for custom form objects, etc.)

does not work for select

validates :country_code, presence: true

translates to

<select name="user[country_code]">

instead of

<select required="required" name="user[country_code]">

"length" validation should add "required" attribute automatically

Hi!

I've noticed that

validates :first_name, length: { minimum: 2, maximum: 50 }

translates to

<input maxlength="50" minlength="2" size="50" type="text">

To be 100% accurate with actual model validation, it should translate to
<input required="required" maxlength="50" minlength="2" size="50" type="text">

If you agree, I could prepare a pull request with that, are you interested?

inclusion support

The following Rails code:

# User model
validates :state, inclusion: { in: ['unconfirmed', 'confirmed', 'locked', 'deleted', 'subaccount'] }

# user edit view
= f.text_field :state

can be translated into the following html code:

<input id="user_state" name="user[state]" type="text" pattern="(unconfirmed)|(confirmed)|(locked)|(deleted)|(subaccount)"/>

Can I send a PR?

Related to #23

Doesn't work with other ORMs besides ActiveRecord

I'm using Mongoid as my object mapper. So since I don't require the ActiveRecord railtie in my app the ActiveRecord on_load hook doesn't run and the ActiveModel helper methods don't get loaded in.

Any chance the loading code could be changed to work with any ActiveModel based mapper?

Highlight all fields that fail validation at the same time

It would be nice if, instead of a single field failing validation being highlighted, the user fixes that field, and then attempts to submit again and they get the next field that failed, that all fields that fail validation are highlighted at the same time. This will provide a better user experience and less steps to get a proper input from the user.

Support for form_with

form_with, introduced in Rails 5.1 can generate form tags based on URLs, scopes or models (before the alternatives were form_for for model instances and form_tag for custom URLs). When including a model, the gem could also generate html validators for it.

undefined method `auto_html5_validation' for Active Model

From my spider test:

[979faece-c1e5-4d78-ac39-0b73b12863c4] [299:68.43] ActionView::Template::Error (undefined method `auto_html5_validation' for Patchinfo:Class):
[979faece-c1e5-4d78-ac39-0b73b12863c4] [299:68.43]     11:             %strong
[979faece-c1e5-4d78-ac39-0b73b12863c4]     12:               = f.label(:packager, 'Packager:')
[979faece-c1e5-4d78-ac39-0b73b12863c4]     13:             %br/
[979faece-c1e5-4d78-ac39-0b73b12863c4]     14:             = f.text_field :packager, required: true
[979faece-c1e5-4d78-ac39-0b73b12863c4]     15:             :javascript
[979faece-c1e5-4d78-ac39-0b73b12863c4]     16:               $("#packager").autocomplete({source: '#{url_for controller: 'user', action: 'autocomplete'}', search: function(event, ui) {
[979faece-c1e5-4d78-ac39-0b73b12863c4]     17:                 $(this).addClass('loading-spinner');
[979faece-c1e5-4d78-ac39-0b73b12863c4] [299:68.43]   
[979faece-c1e5-4d78-ac39-0b73b12863c4] [299:68.43] app/views/webui/patchinfo/_form.html.haml:14:in `block in _app_views_webui_patchinfo__form_html_haml__1383717022713791384_47354342968160'
[979faece-c1e5-4d78-ac39-0b73b12863c4] app/views/webui/patchinfo/_form.html.haml:2:in `_app_views_webui_patchinfo__form_html_haml__1383717022713791384_47354342968160'
[979faece-c1e5-4d78-ac39-0b73b12863c4] app/views/webui/patchinfo/edit.html.haml:3:in `_app_views_webui_patchinfo_edit_html_haml__1907723402339578054_47354343006520'
[979faece-c1e5-4d78-ac39-0b73b12863c4] config/initializers/wrap_parameters.rb:38:in `call'
[979faece-c1e5-4d78-ac39-0b73b12863c4] test/functional/webui/spider_test.rb:99:in `crawl'
[979faece-c1e5-4d78-ac39-0b73b12863c4] test/functional/webui/spider_test.rb:161:in `test_spider_as_admin'
[979faece-c1e5-4d78-ac39-0b73b12863c4] test/test_helper.rb:118:in `block in __run'
[979faece-c1e5-4d78-ac39-0b73b12863c4] test/test_helper.rb:118:in `map'
[979faece-c1e5-4d78-ac39-0b73b12863c4] test/test_helper.rb:118:in `__run'

It only fails for Active Model, not for Active Record.

Regexp support

Hi @amatsuda and thanks for great gem!

I want to know do you have any plans to support Regexp in a future? Seems like this library really helps to avoid duplication between client and server, but with regexp I have to copy them anyway.

Or, maybe you have any advice for that?

I have for example, validation in backend with

value =~ /\A(4|9)\d{7}\Z/

and for frontend:

<%= f.telephone_field(:phone,
         placeholder: 'Mobile',
         pattern: '^[49]\d{7}$') %>

undefined method

I get:

undefined method `auto_html5_validation' for #Class:0x007f11bd92f6a0

My guess is that you require some javascript file to be added to the manifest when not using //= require_tree .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.