diff --git a/src/components/form/main.js b/src/components/form/main.js index 56415a12..107d1b25 100644 --- a/src/components/form/main.js +++ b/src/components/form/main.js @@ -160,6 +160,7 @@ export default class form extends React.Component { validator() { console.log("表单验证") let doms = document.getElementsByClassName("form-Item"); + let self = this; for (let i = 0; i < doms.length; i++) { var com = doms[i].children; let item = com[com.length - 1] @@ -171,31 +172,65 @@ export default class form extends React.Component { let rules_item = _.get(this.state.rules, formItem.props.prop) if (rules_item) { for (let j = 0; j < rules_item.length; j++) { - if (formItem_com.value == "") { - if (rules_item[j].type == "required") { - this.removeClasss(item); - this.isRequired(formItem_com.value, o.className, item, rules_item[j].message); + + + if (rules_item[j].type == "required") { + + if (formItem_com.value == "") { + + self.removeClasss(item) + self.isRequired(formItem_com.value, o.className, item, rules_item[j].message); + break; } - } else { - console.log("规则验证") - - if (rules_item[j].type == "regExp") { - - var regu = rules_item[j].reg; - var re = new RegExp(regu); - let s = formItem_com.value; - if (re.test(s)) { - console.log("满足") - this.removeClasss(item) - } else { - console.log("不满足") - this.isRequired(formItem_com.value, o.className, item, rules_item[j].message); - } - } else { - this.removeClasss(item) + else{ + self.removeClasss(item) } - + } + + if (rules_item[j].type == "regExp") { + + var regu = rules_item[j].reg; + var re = new RegExp(regu); + let s = formItem_com.value; + if (re.test(s)) { + console.log("满足") + self.removeClasss(item) + + } else { + console.log("不满足") + self.isRequired(formItem_com.value, o.className, item, rules_item[j].message); + } + + } + + + + // if (formItem_com.value == "") { + // if (rules_item[j].type == "required") { + // this.removeClasss(item); + // this.isRequired(formItem_com.value, o.className, item, rules_item[j].message); + // } + // } else { + // console.log("规则验证") + + // if (rules_item[j].type == "regExp") { + + // var regu = rules_item[j].reg; + // var re = new RegExp(regu); + // let s = formItem_com.value; + // if (re.test(s)) { + // console.log("满足") + // this.removeClasss(item) + // } else { + // console.log("不满足") + // this.isRequired(formItem_com.value, o.className, item, rules_item[j].message); + // } + // } else { + // this.removeClasss(item) + // } + + // } }