提交按钮在Ruby on Rails中使用jQuery验证无法正常工作 [英] Submit button not working using jQuery validation in ruby on rails

查看:111
本文介绍了提交按钮在Ruby on Rails中使用jQuery验证无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ruby2和rails4.我有使用jQuery的验证.验证错误可以正确显示,但是当我单击提交"按钮时,尽管我为字段指定了正确的值,但它什么也没做.有人可以帮我解决问题吗?我的代码如下所示.谢谢.

I am using ruby2 and rails4. I have the validation using jQuery. The validation errors are shown correctly, but when I click on submit button it does nothing though I had given the correct value for field. Can anybody please help me to solve the problem? My code is shown below. Thank you.

jQuery插件:

http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.js
 http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.min.js

在download.html.erb

In download.html.erb

    <%= form_tag file_download_contacts_path, :method => :post, :id => 'contact-form'  do |f| %>         
  <h3><b>Download Form</b></h3>      
  <div>   

  <div><%=  label_tag :Name  %><br />  
    <%= text_field_tag "contact[name]" , nil, placeholder: "Your Name" %></div>         
<div><%=  label_tag :Email %><br />
    <%= email_field_tag "contact[email]" , nil, placeholder: "your@mail.com" %></div>
<div><%=  label_tag :Mobile %><br />
    <%= telephone_field_tag "contact[phone]" , nil, placeholder: "Your Contact No" %></div>
<div><br/><%= button_tag 'submit' %></div>
  </div>    
 <% end %>              


 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js" type="text/javascript"></script>
<script src="/assets/jquery.validate.js"></script>
<script src="/assets/jquery.validate.min.js"></script>   
<script type="text/javascript">
$(document).ready(function () {
$("#contact-form").validate({
debug: true,
rules: {
"contact[name]": {required: true, max: false, min: false},  
"contact[email]": {required: true, email: true},        
"contact[phone]": {required: true, digits: true, minlength: 10, maxlength: 10}                
}
});
});
</script>           

推荐答案

来自jQuery验证插件文档

From jQuery Validation Plugin documentation

调试(默认:false)

debug (default: false)

类型:布尔值

启用调试模式.如果为true,则不提交表单,并且控制台上会显示某些错误

Enables debug mode. If true, the form is not submitted and certain errors are displayed on the console

只需从验证方法中删除行 debug: true ,您就可以了.

Just remove the line debug: true form your validation method and you'll be okay.

这篇关于提交按钮在Ruby on Rails中使用jQuery验证无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆