直接上代码:
var vm = avalon.define({
$id: "validate2",
firstname: '司徒正美',
lastname: '',
username: '',
password: '',
confirm_password: '',
email: '',
agree: false,
topic: [],
toggle: false,
validate: {
onError: function (reasons) {
reasons.forEach(function (reason) {
console.log(reason.getMessage())
})
},
onValidateAll: function (reasons) {
if (reasons.length) {
console.log('有表单没有通过')
} else {
console.log('全部通过')
}
}
}
})
avalon.validators.checked = {
message: '必须扣上',
get: function (value, field, next) {
next(value)
return value
}
}
avalon.validators.selecttwo = {
message: '至少选择两个',
get: function (value, field, next) {
next(!vm.toggle || value.length >= 2)
return value
}
}
验证完整的表单
名字
姓氏
用户名
密码
验证密码
Email
请同意我们的声明
我乐意接收新信息
主题 (至少选择两个)
Marketflash
Latest fuzz
Mailing list digester
至少选择两个