在我的Rails 3应用程序中等于v 2.0.7不能用于密码确认

时间:2015-05-01 20:30:57

标签: ruby-on-rails parsley.js

我有一个简单的用户登录表单我正在使用parsely js。其他一切工作正常,除非我使用' equalto'这里的功能是我的代码:

<%= form_for @user, data: "data-parsley-validate" do |f|%>
<div class="field">
<%= f.collection_select(:title_id, Title.all, :id, :title_name, {autofocus: true, :prompt => "Title"}, {:class => "labels", :required => true})%>

<div class="field">
<%= f.label :first_name, "First Name *" %><br />
<%= f.text_field :first_name, :required=> true %>
</div>

<div class="field">
<%= f.label :second_name, "Family Name *" %><br />
<%= f.text_field :second_name, :required=> true %>
</div>

<div class="field">
<%= f.label :email, "Email address *" %><br />
<%= f.text_field :email, :type=>"email", :required=>true %>
</div>
<div class="field">
<%= f.label :password, "Password *" %><br />
<%= f.password_field :password, :required => true, :minlength => "8" %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Password Confirmation *" %><br />
<%= f.password_field :password_confirmation,:required=>true, :minlength=>"8", :equalto=>"#user_password"%>
</div>

<div class="actions">
<%= f.submit "Create an Account: move to next step", class: "btn btn-success labels"  %>
</div>
   

1 个答案:

答案 0 :(得分:0)

form_id =用表单标记

写的id
$(document).ready(function () {    
  $("#form_id").validate({
    debug: true,
    rules: {
        "user[password]": {minlength: 6},
        "user[password_confirmation]": {equalTo: "#user_password"}
    }
  });
  jQuery.extend(jQuery.validator.messages, {
    equalTo: "Confirm password should be same as password."
  });
});