Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b0a3265

Browse filesBrowse files
author
davidysxue
committed
fix: form validate
1 parent 783d18f commit b0a3265
Copy full SHA for b0a3265

File tree

Expand file treeCollapse file tree

2 files changed

+93
-96
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+93
-96
lines changed
Open diff view settings
Collapse file

‎src/form/form-validator.ts‎

Copy file name to clipboardExpand all lines: src/form/form-validator.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const validateSingleRule = (rule: any, value: any, param: any = null, models = n
77
const ruleKeys = Object.keys(rule)
88

99
for (let i = 0, l = ruleKeys.length; i < l; ++i) {
10-
const ruleKey = rule[i]
10+
const ruleKey = ruleKeys[i]
1111
if (ruleKey === 'name' || ruleKey === 'message') continue
1212
const validateMethod =
1313
typeof rule.validator !== 'undefined' ? rule.validator : Validator[ruleKey]
Collapse file

‎tools/demo/example/form/form.js‎

Copy file name to clipboardExpand all lines: tools/demo/example/form/form.js
+92-95Lines changed: 92 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -64,104 +64,101 @@ CustomPage({
6464
}},
6565
}]
6666
},
67-
methods: {
68-
radioChange: function (e) {
69-
console.log('radio发生change事件,携带value值为:', e.detail.value);
70-
71-
var radioItems = this.data.radioItems;
72-
for (var i = 0, len = radioItems.length; i < len; ++i) {
73-
radioItems[i].checked = radioItems[i].value == e.detail.value;
74-
}
75-
76-
this.setData({
77-
radioItems: radioItems,
78-
[`formData.radio`]: e.detail.value
79-
});
80-
},
81-
checkboxChange: function (e) {
82-
console.log('checkbox发生change事件,携带value值为:', e.detail.value);
83-
84-
var checkboxItems = this.data.checkboxItems, values = e.detail.value;
85-
for (var i = 0, lenI = checkboxItems.length; i < lenI; ++i) {
86-
checkboxItems[i].checked = false;
87-
88-
for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
89-
if(checkboxItems[i].value == values[j]){
90-
checkboxItems[i].checked = true;
91-
break;
92-
}
67+
radioChange: function (e) {
68+
console.log('radio发生change事件,携带value值为:', e.detail.value);
69+
70+
var radioItems = this.data.radioItems;
71+
for (var i = 0, len = radioItems.length; i < len; ++i) {
72+
radioItems[i].checked = radioItems[i].value == e.detail.value;
73+
}
74+
75+
this.setData({
76+
radioItems: radioItems,
77+
[`formData.radio`]: e.detail.value
78+
});
79+
},
80+
checkboxChange: function (e) {
81+
console.log('checkbox发生change事件,携带value值为:', e.detail.value);
82+
83+
var checkboxItems = this.data.checkboxItems, values = e.detail.value;
84+
for (var i = 0, lenI = checkboxItems.length; i < lenI; ++i) {
85+
checkboxItems[i].checked = false;
86+
87+
for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
88+
if(checkboxItems[i].value == values[j]){
89+
checkboxItems[i].checked = true;
90+
break;
9391
}
9492
}
95-
96-
this.setData({
97-
checkboxItems: checkboxItems,
98-
[`formData.checkbox`]: e.detail.value
99-
});
100-
},
101-
bindDateChange: function (e) {
102-
this.setData({
103-
date: e.detail.value,
104-
[`formData.date`]: e.detail.value
105-
})
106-
},
107-
formInputChange(e) {
108-
const {field} = e.currentTarget.dataset
109-
this.setData({
110-
[`formData.${field}`]: e.detail.value
111-
})
112-
},
113-
bindTimeChange: function (e) {
114-
this.setData({
115-
time: e.detail.value
116-
})
117-
},
118-
bindCountryCodeChange: function(e){
119-
console.log('picker country code 发生选择改变,携带值为', e.detail.value);
120-
121-
this.setData({
122-
countryCodeIndex: e.detail.value
123-
})
124-
},
125-
bindCountryChange: function(e) {
126-
console.log('picker country 发生选择改变,携带值为', e.detail.value);
127-
128-
this.setData({
129-
countryIndex: e.detail.value
130-
})
131-
},
132-
bindAccountChange: function(e) {
133-
console.log('picker account 发生选择改变,携带值为', e.detail.value);
134-
135-
this.setData({
136-
accountIndex: e.detail.value
137-
})
138-
},
139-
bindAgreeChange: function (e) {
140-
this.setData({
141-
isAgree: !!e.detail.value.length
142-
});
143-
},
144-
submitForm() {
145-
this.selectComponent('#form').validate((valid, errors) => {
146-
console.log('valid', valid, errors)
147-
if (!valid) {
148-
const firstError = Object.keys(errors)
149-
if (firstError.length) {
150-
this.setData({
151-
error: errors[firstError[0]].message
152-
})
153-
154-
}
155-
} else {
156-
wx.showToast({
157-
title: '校验通过'
158-
})
159-
}
160-
})
161-
// this.selectComponent('#form').validateField('mobile', (valid, errors) => {
162-
// console.log('valid', valid, errors)
163-
// })
16493
}
16594

95+
this.setData({
96+
checkboxItems: checkboxItems,
97+
[`formData.checkbox`]: e.detail.value
98+
});
99+
},
100+
bindDateChange: function (e) {
101+
this.setData({
102+
date: e.detail.value,
103+
[`formData.date`]: e.detail.value
104+
})
105+
},
106+
formInputChange(e) {
107+
const {field} = e.currentTarget.dataset
108+
this.setData({
109+
[`formData.${field}`]: e.detail.value
110+
})
111+
},
112+
bindTimeChange: function (e) {
113+
this.setData({
114+
time: e.detail.value
115+
})
116+
},
117+
bindCountryCodeChange: function(e){
118+
console.log('picker country code 发生选择改变,携带值为', e.detail.value);
119+
120+
this.setData({
121+
countryCodeIndex: e.detail.value
122+
})
123+
},
124+
bindCountryChange: function(e) {
125+
console.log('picker country 发生选择改变,携带值为', e.detail.value);
126+
127+
this.setData({
128+
countryIndex: e.detail.value
129+
})
130+
},
131+
bindAccountChange: function(e) {
132+
console.log('picker account 发生选择改变,携带值为', e.detail.value);
133+
134+
this.setData({
135+
accountIndex: e.detail.value
136+
})
137+
},
138+
bindAgreeChange: function (e) {
139+
this.setData({
140+
isAgree: !!e.detail.value.length
141+
});
142+
},
143+
submitForm() {
144+
this.selectComponent('#form').validate((valid, errors) => {
145+
console.log('valid', valid, errors)
146+
if (!valid) {
147+
const firstError = Object.keys(errors)
148+
if (firstError.length) {
149+
this.setData({
150+
error: errors[firstError[0]].message
151+
})
152+
153+
}
154+
} else {
155+
wx.showToast({
156+
title: '校验通过'
157+
})
158+
}
159+
})
160+
// this.selectComponent('#form').validateField('mobile', (valid, errors) => {
161+
// console.log('valid', valid, errors)
162+
// })
166163
}
167164
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.