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

支持多个字段required其中之一 #134

Closed
niceue opened this issue Jul 5, 2014 · 0 comments
Closed

支持多个字段required其中之一 #134

niceue opened this issue Jul 5, 2014 · 0 comments

Comments

@niceue
Copy link
Owner

niceue commented Jul 5, 2014

内置规则required又支持新语法啦,groups参数从此就废弃了。

怎样实现,多个字段至少填写一个?

<input class="contact" name="mobile" placeholder="手机号"
    data-rule="required(from, .contact);mobile"
    data-msg-required="请至少填写一种联系方式">

<input class="contact" name="tel" placeholder="电话"
    data-rule="required(from, .contact);tel">

<input class="contact" name="email" placeholder="邮箱"
    data-rule="required(from, .contact);email">

使用规则:required(from, .className, count)

其中:
参数from是固定的,表示required需要执行多项验证;
.className是这一组字段都有的className;
最后一个参数count是可选的(默认为1)

只需要给组内第一个字段设置required的错误消息就可以了(可以是DOM传参或js传参)

@niceue niceue added this to the 0.8.0 milestone Jul 5, 2014
@niceue niceue added the feature label Jul 5, 2014
@niceue niceue closed this as completed in 6fca492 Jul 5, 2014
niceue added a commit that referenced this issue Jul 5, 2014
@niceue niceue changed the title 支持多个字段required之一 支持多个字段required之一(替代groups) Jul 6, 2014
@niceue niceue changed the title 支持多个字段required之一(替代groups) 支持多个字段required其中之一 Jul 12, 2014
@niceue niceue added the new label Jul 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant