Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator works in multi-forms with one function call #33

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

SaitoWu
Copy link

@SaitoWu SaitoWu commented Nov 25, 2013

:shipit: :shipit: :shipit:

e.stopImmediatePropagation();
return errorCallback.call(this, unvalidFields);
} else {
if ($._data($form[0], "events").submit.length > 1) e.preventDefault();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如何测试?另外,$._data 理论上仅 jQuery 内部使用啊

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个暂时我没有别的更好的解决方案, 因为 submit 被这里绑定之后, 别的地方的 $('#form').submit 就没法使用了, 默认 submit 之后会跳转页面.

如果想做一些自己的 Ajax 提交, 不刷新页面就比较不那么直觉. 要在 after 里面处理.

最后这个 commit 如果不是符合 Repo 的需要的话, 你可以 cherry-pick 掉其他的.

暂时我比较需要这个特性, 就是还是可以绑定 submit, 在验证通过的情况下也会生效.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你们现在如何满足这种需求? 所有的 form submit 都刷新页面?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

交给点击的程序是处理,而不是在验证器本身处理,你觉得呢?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是很理解你的意思, 你能举个自己使用 Ajax 提交的例子吗?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after 和 before 默认返回的都是 true 哦,也就是你根本不需要 AOP 切面的时候,就不需要这两个函数。这只是对 AOP 思想的一个支持。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

貌似不太能说的清楚, 来张图吧.

img

在未验证通过的情况下, 用户自己绑定的 submit 也会被执行. 这是不对的...

你可以自己在 http://sofish.github.io/validator.js/ 实验一下.

但是如果是 PR 里面的逻辑, x 是不会被输出的.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我大概猜的出来你的代码是这样验证的:

$(".form").validator({
  after: function(event){
    event.preventDefault();
    // do some evil with ajax
  }
})

但如果这里的 $(".form") 不止一个, after 的逻辑就不可能适应那么多 form..

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你的意思是,当用户也绑定了 submit 事件,要去阻止?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants