提交 8855bdde 编写于 作者: KK's avatar KK

表单校验

上级 3136063b
...@@ -82,22 +82,36 @@ export default class AppFormItem extends Vue { ...@@ -82,22 +82,36 @@ export default class AppFormItem extends Vue {
* @memberof AppFormItem * @memberof AppFormItem
*/ */
@Watch('checkValue') @Watch('checkValue')
checkRule() { checkValueChange(){
this.checkRule();
}
public checkRule(): boolean {
let _this = this
let erro_text :any = ""; let erro_text :any = "";
let isCheck :boolean = true;
let required :boolean = true;
this.rules.forEach((item:any)=>{ this.rules.forEach((item:any)=>{
if(item.hasOwnProperty('pattern') && item.trigger == 'change' && this.checkValue){ if(item.hasOwnProperty('pattern') && item.trigger == 'change' && _this.checkValue){
let pattern: any = item.pattern; let pattern: any = item.pattern;
if(!pattern.test(this.checkValue)){ if(!pattern.test( _this.checkValue)){
erro_text = item.message; erro_text = item.message;
isCheck = false;
} }
} }
if(item.hasOwnProperty('required') && item.trigger == 'change'){ if(item.hasOwnProperty('required') && item.trigger == 'change'){
if(item.required && !this.checkValue){ if(item.required && ! _this.checkValue){
erro_text = item.message; erro_text = item.message;
required = false;
} }
} }
}); });
this.errorText = erro_text; this.errorText = erro_text;
if(isCheck && required){
return true
}else{
return false
}
} }
/** /**
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册