Skip to content

Commit bc4323b

Browse files
authored
[new feature] AddressEdit: add postal-validator prop (youzan#4067)
1 parent f520c22 commit bc4323b

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/address-edit/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export default {
7676
| is-saving | Whether to show save button loading status | `boolean` | `false` |
7777
| is-deleting | Whether to show delete button loading status | `boolean` | `false` |
7878
| tel-validator | The method to validate tel | `(tel: string) => boolean` | - |
79-
| validator | Custom validator | `(key, value) => string` | - | 1.3.9 |
79+
| postal-validator | The method to validate postal | `(tel: string) => boolean` | - |
80+
| validator | Custom validator | `(key, value) => string` | - |
8081

8182
### Events
8283

src/address-edit/README.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export default {
7575
| is-saving | 是否显示保存按钮加载动画 | `boolean` | `false` | - |
7676
| is-deleting | 是否显示删除按钮加载动画 | `boolean` | `false` | - |
7777
| tel-validator | 手机号格式校验函数 | `string => boolean` | - | - |
78+
| postal-validator | 邮政编码格式校验函数 | `string => boolean` | - | 2.1.2 |
7879
| validator | 自定义校验函数 | `(key, value) => string` | - | - |
7980

8081
### Events

src/address-edit/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const defaultData = {
2424
isDefault: false
2525
};
2626

27+
function isPostal(value) {
28+
return /^\d{6}$/.test(value);
29+
}
30+
2731
export default createComponent({
2832
props: {
2933
areaList: Object,
@@ -60,6 +64,10 @@ export default createComponent({
6064
telValidator: {
6165
type: Function,
6266
default: isMobile
67+
},
68+
postalValidator: {
69+
type: Function,
70+
default: isPostal
6371
}
6472
},
6573

@@ -183,7 +191,7 @@ export default createComponent({
183191
case 'addressDetail':
184192
return value ? '' : t('addressEmpty');
185193
case 'postalCode':
186-
return value && !/^\d{6}$/.test(value) ? t('postalEmpty') : '';
194+
return value && !this.postalValidator(value) ? t('postalEmpty') : '';
187195
}
188196
},
189197

0 commit comments

Comments
 (0)