使用 ajax 进行实时验证轨道 3
我正在使用 ruby on Rails 3. 以及 UJS 和 jquery 我正在尝试生成 AJAX 表单。 正如我们所知,即使它是 AJAX,该表单仍保持为普通表单,仅添加了 remote-data=>true。
动态检查表单是否为remote-data=>true,然后执行ajax 请求。
现在,单击提交按钮后如何执行实时验证。
我想要的是.-- 单击提交按钮时,所有验证都应在客户端执行,然后如果一切顺利,我希望提交表单。如果有任何错误,则不应提交该表格。
一个想法?
I am using ruby on rails 3. with UJS and jquery
I am trying to generate an AJAX form.
As we know that the form remains as a normal form even though it is AJAX only remote-data=>true gets added.
The form is checked on the fly for remote-data=>true and then it performs and ajax request.
Now How do I perform live validation after the submit button is clicked.
What I want is .--
When the submit button is clicked all the valications should be performed on client side and then if everything is perfect I want the form to be submitted. If there are any eroors the form should not be submitted.
An idea ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试这样做
因此,每个远程表单都会检查字段是否有效。
如果字段有效,则 ajax:before send 返回 true,否则返回 false。
注意:Validate_fields 是用户定义的函数,用于检查验证。
I tried doing this
so every form which is a remote form check if the fields are valid.
If the fields are valid the return true from ajax:before send else return false.
Note : Validate_fields is user-defined function to check for validations.
查看这两篇文章:
验证插件是开箱即用的“onSubmit”响应式。
教程中也应该附带实现 ajax 验证。
http://docs.jquery.com/Plugins/Validation
http://sleekd.com/tutorials/jquery-validation-in-ruby-on-rails/
Check out this two Posts:
the validate plugin is out of the box "onSubmit" responsive.
With the tutorial should should come along to implement ajax validation as well.
http://docs.jquery.com/Plugins/Validation
http://sleekd.com/tutorials/jquery-validation-in-ruby-on-rails/