提交按钮不起作用使用jquary验证在Ruby on Rails的 [英] submit button not working using jquary validation in ruby on rails

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

问题描述

我使用ruby2和rails4。我已经使用jquery的验证。验证错误被正确显示,但是当我点击提交按钮,它什么都不做,虽然我给了现场的正确值。任何机构可以请帮我解决这个问题?我的codeS如下。谢谢你。

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

 <%=的form_tag file_download_contacts_path,:方法=> :帖子,:ID => 接触的形式做| F | %>
  < H3>< B>下载表格及LT; / B>< / H3>
  < D​​IV>

  < D​​IV><%= label_tag:名称%>< BR />
    <%= text_field_tag​​接触[名],无,占位符:你的名字%>< / DIV>
< D​​IV><%= label_tag:电子邮件%>< BR />
    <%= email_field_tag​​接触[邮件],无,占位符:your@mail.com%>< / DIV>
< D​​IV><%= label_tag:移动%GT;< BR />
    <%= telephone_field_tag​​联系人[手机],无,占位符:你跟不%>< / DIV>
< D​​IV>< BR /><%= button_tag提交%>< / DIV>
  < / DIV>
 <%结束%GT;


 <脚本SRC =htt​​ps://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js类型=文/ JavaScript的>< / SCRIPT>
<脚本的src =/资产/ jquery.validate.js>< / SCRIPT>
<脚本的src =/资产/ jquery.validate.min.js>< / SCRIPT>
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
$(#联系形式)。验证({
调试:真实,
规则:{
接触[名]:{要求:真正的,最大:假的,分:假},
接触[邮件]:{要求:真实,电子邮件:真实},
联系人[手机]:{要求:真实,数字:真,MINLENGTH:10,最大长度:10}
}
});
});
< / SCRIPT>
 

解决方案

从jQuery验证插件文件

  

调试(默认:FALSE)

     

类型:布尔

     

启用调试模式。如果为true,表单没有提交,并显示某些错误控制台上

只是删除​​行调试:真正的形成你的验证方法,你会好起来的。

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 any body please help me to solve the problem? My codes are given below. Thank you.

jQuery plugin:

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

    <%= 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

debug (default: false)

Type: Boolean

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

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

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

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