简体   繁体   English

在ruby on rails上使用jQuery验证提交按钮不起作用

[英]Submit button not working using jQuery validation in ruby on rails

I am using ruby2 and rails4. 我正在使用ruby2和rails4。 I have the validation using jQuery. 我使用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 plugin: 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

In download.html.erb 在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>           

From jQuery Validation Plugin documentation 来自jQuery Validation Plugin文档

debug (default: false) debug(默认值:false)

Type: Boolean 类型:布尔值

Enables debug mode. 启用调试模式。 If true, the form is not submitted and certain errors are displayed on the console 如果为true,则表单未提交,并且控制台上会显示某些错误

Just remove the line debug: true form your validation method and you'll be okay. 只需删除debug: truedebug: true形成您的验证方法,您就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM