Add checkbox validation and error messaging for required options
This commit is contained in:
parent
e740c4bb1a
commit
0cad1e7787
10
src/App.vue
10
src/App.vue
@ -127,6 +127,16 @@ export default {
|
||||
type: 'error',
|
||||
});
|
||||
return;
|
||||
} else if (item.type === 'checkbox' && item.required) {
|
||||
this.itemStatus.answer = this.itemStatus.answer === undefined ? [] : this.itemStatus.answer;
|
||||
const { minOpts, maxOpts } = Object.assign({ minOpts: 1, maxOpts: item.optTexts.length }, item);
|
||||
if (this.itemStatus.answer.length < minOpts || this.itemStatus.answer.length > maxOpts) {
|
||||
ElMessage({
|
||||
message: sprintf(lang[this.settings.lang].checkboxOutOfRange, minOpts, maxOpts),
|
||||
type: 'error',
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
item.answer = this.itemStatus.answer;
|
||||
|
@ -6,6 +6,7 @@ export default {
|
||||
'loading': 'Loading...',
|
||||
'input': 'Please input',
|
||||
'required': 'This field is required',
|
||||
'checkboxOutOfRange': 'Please select at least %d and at most %d option(s)',
|
||||
},
|
||||
'zh-CN': {
|
||||
'submit': '提交',
|
||||
@ -14,5 +15,6 @@ export default {
|
||||
'loading': '加载中...',
|
||||
'input': '请输入',
|
||||
'required': '此字段不能为空',
|
||||
'checkboxOutOfRange': '请选择 %d 到 %d 个选项',
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue
Block a user