[英]jquery validate input array and passing dynamic values
I'm trying to validate a group of input arrays using jquery validator plugin. 我正在尝试使用jquery验证程序插件来验证一组输入数组。 I'm having problems understanding how to pass another element into the validation. 我在理解如何将另一个元素传递到验证时遇到问题。
My code so far: 到目前为止,我的代码:
$('#edit-fixtures').validate({
rules: {
"player_a[]": {
required: true,
uniqueMatch: function () {
return $(this).next('.player').val();
},
},
"player_b[]": {
required: true,
uniqueMatch: function () {
$(this).closest('.player').val();
},
},
}
});
My input elements are a series of paired select boxes named player_a[]
player_b[]
There are about 40 pairs. 我的输入元素是一系列成对的选择框,命名为player_a[]
player_b[]
。大约有40对。 Each pair should be unique and that's what i'll be validating. 每对应该是唯一的,这就是我要验证的。
I'm trying to pass the value of the nearest player_b to the changed player_a and vice versa. 我正在尝试将最近的player_b的值传递给已更改的player_a,反之亦然。
I have a change method to validate on each change: 我有一个更改方法可以对每个更改进行验证:
$(".player").change(function () {
var check = $(this).valid();
console.log("validation:", check);
});
I'm still working on the validation method but cant seem to get the parameters to the method correctly. 我仍在研究验证方法,但似乎无法正确获取方法的参数。
Is there a way of doing this? 有办法吗?
uniqueMatch: [$item1, $item2, ....]
$.validator.addMethod('uniqueMatch', function(value, element, parameterValue) {
var item1Value = $(parameterValue[0]).val();
//and so on...
//Based on values, you return true or false;
//Voila!
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.