语义 ui 表单验证问题
semantic ui Form validation issue
我尝试使用 'Semantic Form Validation' 插件来验证输入长度,如下所示:
$('.ui.form').form({
fields: {
firstname: {
identifier: 'firstname',
rules: [{
type: 'empty',
prompt: 'Please enter your name'
}]
},
lastname: {
identifier: 'lastname',
rules: [{
type: 'empty',
prompt: 'Please enter your name'
}]
},
username: {
identifier: 'username',
rules: [{
type: 'minLength[3]',
prompt: 'Please enter a username'
}]
},
password: {
identifier: 'password',
rules: [{
type: 'minLength[6]',
prompt: 'Please enter a password'
}]
},
terms: {
identifier: 'terms',
rules: [{
type: 'checked',
prompt: 'You must agree to the terms and conditions'
}]
}
}
});
每一行都可以正常工作,但它不会验证 minLength
规则并不断出现错误。它说
Form: There is no rule matching the one you specified minLength
我今天遇到了同样的问题。我尝试了很多变化。然后我去寻找 semantic.js 源代码中对 minLength 的任何引用(那里什么也没有!..)。然后我偶然发现了名为 length
的函数
length .. // is at least string length
length: function(value, requiredLength) {
return (value !== undefined)
? (value.length >= requiredLength)
: false
;
},
// 所以我想我会试一试,结果如你所料..
password: {
identifier: 'password',
rules: [{
type: 'length[6]',
prompt: 'Please enter a password'
}]
},
// 我使用的是语义版本 UI - 2.0.0。
我仍然在为语义 ui 的这个特性苦苦挣扎,我无法让 shorthand 语法工作,也找不到一种方法让每个字段有多个标准..任何建议?
我尝试使用 'Semantic Form Validation' 插件来验证输入长度,如下所示:
$('.ui.form').form({
fields: {
firstname: {
identifier: 'firstname',
rules: [{
type: 'empty',
prompt: 'Please enter your name'
}]
},
lastname: {
identifier: 'lastname',
rules: [{
type: 'empty',
prompt: 'Please enter your name'
}]
},
username: {
identifier: 'username',
rules: [{
type: 'minLength[3]',
prompt: 'Please enter a username'
}]
},
password: {
identifier: 'password',
rules: [{
type: 'minLength[6]',
prompt: 'Please enter a password'
}]
},
terms: {
identifier: 'terms',
rules: [{
type: 'checked',
prompt: 'You must agree to the terms and conditions'
}]
}
}
});
每一行都可以正常工作,但它不会验证 minLength
规则并不断出现错误。它说
Form: There is no rule matching the one you specified minLength
我今天遇到了同样的问题。我尝试了很多变化。然后我去寻找 semantic.js 源代码中对 minLength 的任何引用(那里什么也没有!..)。然后我偶然发现了名为 length
的函数length .. // is at least string length
length: function(value, requiredLength) {
return (value !== undefined)
? (value.length >= requiredLength)
: false
;
},
// 所以我想我会试一试,结果如你所料..
password: {
identifier: 'password',
rules: [{
type: 'length[6]',
prompt: 'Please enter a password'
}]
},
// 我使用的是语义版本 UI - 2.0.0。
我仍然在为语义 ui 的这个特性苦苦挣扎,我无法让 shorthand 语法工作,也找不到一种方法让每个字段有多个标准..任何建议?