Livevalidation和复选框,收音机,选择组 [英] Livevalidation and group of checkbox, radio, select

查看:59
本文介绍了Livevalidation和复选框,收音机,选择组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Livevalidation脚本非常适合验证表单,但您可以选择使用复选框,广播和选择组。见网站: http://www.livevalidation.com/

Livevalidation script is great to validate forms but how you 're suppose to do with group of checkbox, radio, and select. see website : http://www.livevalidation.com/

推荐答案

虽然LiveValidation会对你不利,但可以这样做。你不能将验证器附加到输入类型=radio。

It can be done, though LiveValidation will fight you. You can't attach a validator to an input type="radio".

所以我所做的是添加一个虚拟输入元素,如:

So what I have done is add a dummy input element something like:

<input id="foo" type="text" style="display: none;" value="1" />

到我的表单,然后添加一个Validate.Custom。自定义验证函数类似于

to my form, then add a Validate.Custom to that. The custom validation function would be something like

function () {
    return $('input[name=myRadioName]:checked').length;
}

这是我使用独立的LiveValidation和jQuery所做的事情。如果您正在使用该版本,可能可以使用prototype.js做类似的事情。一个问题是你必须为你的虚拟输入元素分配一个值属性,因为LiveValidation似乎跳过没有值的输入(当然除了Validate.Presence)。

This is what I did using the standalone LiveValidation and jQuery; probably can do something similar with prototype.js if you're using that version. One gotcha is that you must assign a value attribute to your dummy input element, because LiveValidation seems to skip inputs that have no value (excepting of course Validate.Presence).

这篇关于Livevalidation和复选框,收音机,选择组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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