[improvement] AddressEdit: add validator prop (#1971)

This commit is contained in:
neverland
2018-10-24 20:56:05 +08:00
committed by GitHub
parent 368a2eaf94
commit 32da15c647
3 changed files with 15 additions and 8 deletions

View File

@@ -4,7 +4,6 @@
<field
v-model="data.name"
clearable
maxlength="15"
:label="$t('name')"
:placeholder="$t('namePlaceholder')"
:error="errorInfo.name"
@@ -125,6 +124,7 @@ export default create({
areaList: Object,
isSaving: Boolean,
isDeleting: Boolean,
validator: Function,
showDelete: Boolean,
showPostal: Boolean,
showSetDefault: Boolean,
@@ -263,9 +263,16 @@ export default create({
},
getErrorMessage(key) {
const value = String(this.data[key]).trim();
const value = String(this.data[key] || '').trim();
const { $t } = this;
if (this.validator) {
const message = this.validator(key, value);
if (message) {
return message;
}
}
switch (key) {
case 'name':
return value ? '' : $t('nameEmpty');