How to use jquery validation plugin in rails

后端 未结 3 513
被撕碎了的回忆
被撕碎了的回忆 2021-02-06 19:49

How to use jquery validation plugin for the rails form given below.

I want complete steps about how to make the it for different fields

相关标签:
3条回答
  • 2021-02-06 20:10

    Got the solution to add range ,min ,max etc

    we have to use

       <%= f.text_field :mobile,:class => "required number",:minlength=>"10",
       :maxlength=>"10"%>
    

    the above for mobile

    0 讨论(0)
  • 2021-02-06 20:14

    First include the jquery validation file in your layout. Then in rails form add class to validation required fields as <%= f.text_field :firstname, :class => "required" %>. Then write a method with form_id to trigger the validation. That is you have to give like

    $(document).ready(function () { 
       $("your_form_id").validate();  
    }); 
    
    0 讨论(0)
  • 2021-02-06 20:14

    You can use the jquery validation rails gem based on jquery validation plugin. To use it

    1. Add the gem to your gemfile gem 'jquery-validation-rails'
    2. On your app/assets/javascripts/application.js add the following lines

      //= require jquery.validate.additional-methods //= require jquery.validate

    3. As of turbolinks 5 which is included in rails 5 instead of using $(document).ready use $(document).on "turbolinks:load" as described in turbolinks readme
    0 讨论(0)
提交回复
热议问题