[英]jQuery validation built in rule with depends
I want to use min: 1
but I only want the rule to apply under some condition--which I think I can give in a depends function. 我想使用
min: 1
但我只希望规则在某些条件下适用-我认为我可以提供一个depends函数。
I want something like 我想要类似的东西
rules: {
field: {
min: 1,
depends: function(element) {
return element.disabled == false;
}
}
}
See here for something similar https://stackoverflow.com/a/1090847/1333713 看到这里类似的东西https://stackoverflow.com/a/1090847/1333713
My rules above will still apply the min
rule. 我上面的规则仍将应用
min
规则。 How can I get it to respect my depends
? 我怎样才能尊重自己的
depends
呢?
To pass parameters to rules that require them, set a property named param
. 要将参数传递给需要它们的规则,请设置一个名为
param
的属性。 Like this, 像这样,
rules: {
myInputField: {
min: {
depends: function(element) {
return element.disabled == false;
},
param: 1
}
}
}
Summary: when the validator validates myInputField
, it will run the depends
function to see if it should apply the min
rule. 简介:验证器验证
myInputField
,它将运行depends
函数以查看是否应应用min
规则。 If the depends
function evaluates to true, the validator applies the min
rule with the parameter 1
. 如果
depends
函数求值为true,则验证器将min
规则应用于参数1
。 This is the way to conditionally apply rules that take parameters. 这是有条件地应用带有参数的规则的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.