如何将 Twitter Bootstrap 弹出框用于 jQuery 验证通知? [英] How to use Twitter Bootstrap popovers for jQuery validation notifications?

查看:23
本文介绍了如何将 Twitter Bootstrap 弹出框用于 jQuery 验证通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以很容易地使用 bootstrap 使弹出框出现,而且我还可以使用标准 jQuery 验证插件jQuery 验证引擎,但我不知道如何将一个输入另一个.

I can make popovers appear using bootstrap easily enough, and I can also do validations using the standard jQuery validation plugin or the jQuery validation engine, but I can't figure out how to feed one into the other.

我认为我需要的是一些钩子,当验证器想要显示通知时调用它,给它一个闭包,将消息和目标元素传递给弹出窗口.这似乎是一种依赖注入.

I think what I need is some hook which is called by the validator when it wants to display a notification, give it a closure that passes the message and the target element to a popover. This seems like a kind of dependency injection.

理论上一切都很好,但我就是无法弄清楚那个钩子在哪里,或者即使在任一验证引擎中都存在一个钩子.当我所追求的只是错误类型(我什至不一定需要消息文本)和它相关的元素时,他们似乎都打算负责显示带有各种精心设计的布局,包装器,样式选项的通知到.我找到了整个表单的挂钩,而不是单个通知.

All nice in theory, but I just can't figure out where that hook is, or even if one exists in either validation engine. They both seem intent on taking responsibility for displaying notifications with all kinds of elaborate options for placement, wrappers, styles when all I'm after is the error type(s) (I don't necessarily even need message text) and element it relates to. I've found hooks for the entire form, not the individual notifications.

我更喜欢使用类来定义规则的验证系统,因为它们可以很好地与动态创建的表单一起使用.

I much prefer validation systems that use classes to define rules, as they play nicely with dynamically created forms.

有人有解决方案或更好的主意吗?

Anyone have a solution or a better idea?

推荐答案

看看 highlightshowErrors jQuery Validator 选项,这些将让您挂钩触发 Bootstrap 弹出窗口的自定义错误突出显示.

Take a look at the highlight and showErrors jQuery Validator options, these will let you hook in your own custom error highlights that trigger Bootstrap popovers.

这篇关于如何将 Twitter Bootstrap 弹出框用于 jQuery 验证通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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