简体   繁体   English

Rails中的简单客户端验证

[英]Simple Client Side Validations in Rails

Basically, I have 10 validations on a form in my Rails app. 基本上,我在Rails应用程序中的表单上有10个验证。 If there are errors, the page refreshes & shows the errors in a box. 如果有错误,页面将刷新并在框中显示错误。

How can I show the error box without refreshing? 如何显示错误框而无需刷新? I would like the box to display after clicking submit. 我希望在单击提交后显示该框。

I saw a railscasts episode on client side validations using a gem but it seemed a bit too much & complicated for what I'm going after, plus I couldn't get it working. 我在使用gem的客户端验证中看到了一个railscasts片段,但是对于我要执行的操作而言,它似乎太复杂了,而且我无法使其正常工作。 Looking through some of SO's similar questions, I know I'll have to use jquery/java but I'm still sort of lost. 通过SO的一些类似问题,我知道我将不得不使用jquery / java,但我仍然有些失落。 Could someone point me in the right direction 有人能指出我正确的方向吗

Thank you in advance. 先感谢您。

You may want to consider either rolling your own client-side solution, or using a Javascript/jQuery library. 您可能要考虑采用自己的客户端解决方案,或者使用Javascript / jQuery库。

Personally, I've had a lot of luck with jQuery.validationEngine . 就个人而言,我对jQuery.validationEngine很幸运。 It enables configurable and extensible form validations which work well out-of-the-box: 它启用了可配置和可扩展的表单验证,这些验证即开即用:

在此处输入图片说明

And while I haven't tried it myself, jquery-validation seem to be another popular client side validation library. 虽然我自己还没有尝试过,但jquery-validation似乎是另一个流行的客户端验证库。

There are surely many other libraries out there for doing what you're looking to accomplish, but I'm fairly confident there's a good reason why these two are among the most popular solution. 当然,还有许多其他库可以用来完成您要完成的任务,但是我很有把握地相信这两个是最受欢迎的解决方案中的一个很好的理由。 Additionally, both are well-documented and lay out concise instructions for simple implementations on their respective GitHub pages. 此外,两者都有详细的文档,并在各自的GitHub页面上列出了简单实现的简洁说明。

You can try https://github.com/jbmyid/rails_jq_validations 您可以尝试https://github.com/jbmyid/rails_jq_validations

This is too simple to use. 这太简单了。

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

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