Validator works in multi-forms with one function call#33
Validator works in multi-forms with one function call#33SaitoWu wants to merge 25 commits intosofish:masterfrom
Conversation
SaitoWu
commented
Nov 25, 2013
![]()
There was a problem hiding this comment.
如何测试?另外,$._data 理论上仅 jQuery 内部使用啊
There was a problem hiding this comment.
这个暂时我没有别的更好的解决方案, 因为 submit 被这里绑定之后, 别的地方的 $('#form').submit 就没法使用了, 默认 submit 之后会跳转页面.
如果想做一些自己的 Ajax 提交, 不刷新页面就比较不那么直觉. 要在 after 里面处理.
最后这个 commit 如果不是符合 Repo 的需要的话, 你可以 cherry-pick 掉其他的.
暂时我比较需要这个特性, 就是还是可以绑定 submit, 在验证通过的情况下也会生效.
There was a problem hiding this comment.
你们现在如何满足这种需求? 所有的 form submit 都刷新页面?
There was a problem hiding this comment.
不是很理解你的意思, 你能举个自己使用 Ajax 提交的例子吗?
There was a problem hiding this comment.
after 和 before 默认返回的都是 true 哦,也就是你根本不需要 AOP 切面的时候,就不需要这两个函数。这只是对 AOP 思想的一个支持。
There was a problem hiding this comment.
貌似不太能说的清楚, 来张图吧.
在未验证通过的情况下, 用户自己绑定的 submit 也会被执行. 这是不对的...
你可以自己在 http://sofish.github.io/validator.js/ 实验一下.
但是如果是 PR 里面的逻辑, x 是不会被输出的.
There was a problem hiding this comment.
我大概猜的出来你的代码是这样验证的:
$(".form").validator({
after: function(event){
event.preventDefault();
// do some evil with ajax
}
})但如果这里的 $(".form") 不止一个, after 的逻辑就不可能适应那么多 form..