[new feature] AddressEdit: add postal-validator prop (#4067)

This commit is contained in:
neverland 2019-08-08 19:08:46 +08:00 committed by GitHub
parent f520c221a9
commit bc4323b128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -76,7 +76,8 @@ export default {
| is-saving | Whether to show save button loading status | `boolean` | `false` |
| is-deleting | Whether to show delete button loading status | `boolean` | `false` |
| tel-validator | The method to validate tel | `(tel: string) => boolean` | - |
| validator | Custom validator | `(key, value) => string` | - | 1.3.9 |
| postal-validator | The method to validate postal | `(tel: string) => boolean` | - |
| validator | Custom validator | `(key, value) => string` | - |
### Events

View File

@ -75,6 +75,7 @@ export default {
| is-saving | 是否显示保存按钮加载动画 | `boolean` | `false` | - |
| is-deleting | 是否显示删除按钮加载动画 | `boolean` | `false` | - |
| tel-validator | 手机号格式校验函数 | `string => boolean` | - | - |
| postal-validator | 邮政编码格式校验函数 | `string => boolean` | - | 2.1.2 |
| validator | 自定义校验函数 | `(key, value) => string` | - | - |
### Events

View File

@ -24,6 +24,10 @@ const defaultData = {
isDefault: false
};
function isPostal(value) {
return /^\d{6}$/.test(value);
}
export default createComponent({
props: {
areaList: Object,
@ -60,6 +64,10 @@ export default createComponent({
telValidator: {
type: Function,
default: isMobile
},
postalValidator: {
type: Function,
default: isPostal
}
},
@ -183,7 +191,7 @@ export default createComponent({
case 'addressDetail':
return value ? '' : t('addressEmpty');
case 'postalCode':
return value && !/^\d{6}$/.test(value) ? t('postalEmpty') : '';
return value && !this.postalValidator(value) ? t('postalEmpty') : '';
}
},