jQuery 验证插件 - 一旦表单有效
关于 jQuery 验证的问题。当我的表单加载时,我的提交按钮的不透明度为 50%,让用户知道它已被禁用。
一旦表单满足所有规则,onkeyup,我如何检测到这一点并允许我将提交按钮的不透明度返回到 100%。
“ success: function(label) {” 已经太晚了,因为要求用户转到下一个字段,这不是我的应用程序中的工作方式。
有想法吗?
Question about jQuery Validate. When my form loads, I have the submit button at 50% opacity to let the user know it's disabled.
As soon as the form meets all the rules, onkeyup, how do I detect that and allow me to return the submit buttons opacity to 100%.
The " success: function(label) {" is to late, as the requiers the user to have moved on to the next field which isn't the way it works in my app.
Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用验证方法选项轻松劫持验证机制回调。这是一个示例(也将其放在 jsbin 上):
这里的关键是在任何用户之前触发验证输入(使用 validator.form() 方法),因此 jquery.validate 启动监听输入事件,并在按键(和其他)事件触发时开始触发回调。
You can easily hijack the validation mechanism callbacks using the validate method options. Here is an example (also put it on jsbin):
The key here is to trigger the validation before any user input (using the validator.form() method), so jquery.validate starts listening to the input events, and starts triggering the callbacks when the key (and other) events fire.
我用其他方式做这个。
您在服务器上有表单验证,确定吗?为什么要验证表单数据两次?在客户端和服务器上。
我的解决方案是使用ajax将表单发送到服务器,在那里进行验证,如果没有错误-保存数据(或其他东西......)。
如果服务器验证器发现一些错误,则会返回表单(在 json...)并在客户端上显示错误。
帮忙这个?
马丁
I make this in other way.
You have form validation on server, sure?. And why validate form data twice? In client, and on server.
My solution is send form with ajax to server, validate there, and if is no error - save data (or something...).
If server validator find some errors, form is returned (on json...) and errors is displayed on client.
Help this?
Martin