mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[new feature] AddressEdit: add postal-validator prop (#4067)
This commit is contained in:
parent
f520c221a9
commit
bc4323b128
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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') : '';
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user