Formvalidation.io 和带索引的数组输入字段
Formvalidation.io and array input fields with index
我正在使用 Formvalidation.io 插件,它与
完美配合
<input type="text" name="url[]" required />
使用以下验证码
'url[]': {
validators: {
stringLength: {
min: 4
}
}
},
但是当使用 "predefined" 索引时
<input type="text" name="url[1]" required />
以下验证无效
'url[]': {
validators: {
stringLength: {
min: 4
}
}
},
它在验证代码中使用固定索引(见下面的代码)
'url[1]': {
validators: {
stringLength: {
min: 4
}
}
},
但是我正在动态添加具有未知索引的字段。
所以在验证码中使用固定索引不是一个选项。
我认为您正在寻找的答案在 this 页面上,然后是第二部分 "Inputs with different names"。
你可以在 css class 上验证你是否飞过
<fieldname>: {
//the input css class
selector: '<.cssClass>',
// The field is placed inside .col-xs-6 div instead of .form-group
row: '.col-xs-6',
validators: {
<your validator>
}
}
对于 formvalidation.io 版本 1.9.0,这对我有用:
<input type="text" name="myvar[1]" />
<input type="text" name="myvar[2]" />
<input type="text" name="myvar[3]" />
使用 selector
选项验证所有以“myvar[”开头的变量名[
'this_can_be_anything': {
selector: 'input[name^="myvar["]',
validators: {
stringLength: {
min: 4
}
}
},
可以在此处找到更多详细信息:
https://formvalidation.io/guide/getting-started/field-selector/
我正在使用 Formvalidation.io 插件,它与
完美配合<input type="text" name="url[]" required />
使用以下验证码
'url[]': {
validators: {
stringLength: {
min: 4
}
}
},
但是当使用 "predefined" 索引时
<input type="text" name="url[1]" required />
以下验证无效
'url[]': {
validators: {
stringLength: {
min: 4
}
}
},
它在验证代码中使用固定索引(见下面的代码)
'url[1]': {
validators: {
stringLength: {
min: 4
}
}
},
但是我正在动态添加具有未知索引的字段。 所以在验证码中使用固定索引不是一个选项。
我认为您正在寻找的答案在 this 页面上,然后是第二部分 "Inputs with different names"。
你可以在 css class 上验证你是否飞过
<fieldname>: {
//the input css class
selector: '<.cssClass>',
// The field is placed inside .col-xs-6 div instead of .form-group
row: '.col-xs-6',
validators: {
<your validator>
}
}
对于 formvalidation.io 版本 1.9.0,这对我有用:
<input type="text" name="myvar[1]" />
<input type="text" name="myvar[2]" />
<input type="text" name="myvar[3]" />
使用 selector
选项验证所有以“myvar[”开头的变量名[
'this_can_be_anything': {
selector: 'input[name^="myvar["]',
validators: {
stringLength: {
min: 4
}
}
},
可以在此处找到更多详细信息: https://formvalidation.io/guide/getting-started/field-selector/