Update main.js

This commit is contained in:
北海一刀 2021-11-11 17:34:01 +08:00
parent 5aaa62bb7b
commit 7122d1f4a0
1 changed files with 57 additions and 22 deletions

View File

@ -160,6 +160,7 @@ export default class form extends React.Component {
validator() { validator() {
console.log("表单验证") console.log("表单验证")
let doms = document.getElementsByClassName("form-Item"); let doms = document.getElementsByClassName("form-Item");
let self = this;
for (let i = 0; i < doms.length; i++) { for (let i = 0; i < doms.length; i++) {
var com = doms[i].children; var com = doms[i].children;
let item = com[com.length - 1] let item = com[com.length - 1]
@ -171,13 +172,21 @@ export default class form extends React.Component {
let rules_item = _.get(this.state.rules, formItem.props.prop) let rules_item = _.get(this.state.rules, formItem.props.prop)
if (rules_item) { if (rules_item) {
for (let j = 0; j < rules_item.length; j++) { for (let j = 0; j < rules_item.length; j++) {
if (formItem_com.value == "") {
if (rules_item[j].type == "required") { if (rules_item[j].type == "required") {
this.removeClasss(item);
this.isRequired(formItem_com.value, o.className, item, rules_item[j].message); if (formItem_com.value == "") {
self.removeClasss(item)
self.isRequired(formItem_com.value, o.className, item, rules_item[j].message);
break;
}
else{
self.removeClasss(item)
}
} }
} else {
console.log("规则验证")
if (rules_item[j].type == "regExp") { if (rules_item[j].type == "regExp") {
@ -186,17 +195,43 @@ export default class form extends React.Component {
let s = formItem_com.value; let s = formItem_com.value;
if (re.test(s)) { if (re.test(s)) {
console.log("满足") console.log("满足")
this.removeClasss(item) self.removeClasss(item)
} else { } else {
console.log("不满足") console.log("不满足")
this.isRequired(formItem_com.value, o.className, item, rules_item[j].message); self.isRequired(formItem_com.value, o.className, item, rules_item[j].message);
}
} else {
this.removeClasss(item)
} }
} }
// 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)
// }
// }
} }
} }