Skip to content

Commit

Permalink
Feat validatefields (#2103)
Browse files Browse the repository at this point in the history
* feat: FormRef.clearValidate 方法支持传 names 参数,清空指定字段

* feat version 2.0.15
  • Loading branch information
leehaoChen authored Apr 11, 2024
1 parent d1f2c15 commit 63bc43f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shineout",
"version": "2.0.15-beta.4",
"version": "2.1.0-rc.1",
"description": "Shein 前端组件库",
"main": "./lib/index.js",
"module": "./es/index.js",
Expand Down
3 changes: 3 additions & 0 deletions site/pages/documentation/changelog-rc/2.x.x.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# 更新日志
### 2.1.0-rc.1
- FormRef.clearValidate 方法支持传 names 参数,清空指定字段

### 2.0.0-rc.19
- 修复 Popover 在 Table 中可能导致其他弹层组件下拉列表失效的问题

Expand Down
2 changes: 1 addition & 1 deletion site/pages/documentation/changelog/2.x.x.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 更新日志

### 2.0.15-beta.2
### 2.0.15

- Table 当无数据的时候关闭 sticky (< 2.0.15)
- 修复 Menu disabled 没有效果的问题 (< 2.0.15)
Expand Down
12 changes: 7 additions & 5 deletions src/Datum/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,13 @@ export default class<V extends ObjectType> {
return promiseAll(validates)
}

validateClear() {
const keys = Object.keys(this.$validator)
validateClear(names?: string[]) {
const keys = names || Object.keys(this.$validator)
const validates = keys.map(k => this.$validator[k](FORCE_PASS))
Promise.all(validates).then(() => {
this.$errors = {}
})
if (!names) {
Promise.all(validates).then(() => {
this.$errors = {}
})
}
}
}
4 changes: 2 additions & 2 deletions src/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class Form<Value> extends Component<SimpleFormProps<Value>> {
validate: () => this.props.datum.validate(),
validateFields: fields => this.props.datum.validateFields(fields).catch(() => {}),
validateFieldsWithError: fields => this.props.datum.validateFields(fields),
clearValidate: () => {
this.props.datum.validateClear()
clearValidate: (names?: string[]) => {
this.props.datum.validateClear(names)
},
submit: (withValidate = true) => {
if (withValidate) this.handleSubmit()
Expand Down
6 changes: 3 additions & 3 deletions src/Form/Props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,10 @@ export interface FormRef<Value> {
*/
validateFieldsWithError: (fields: string | string[]) => Promise<any>
/**
* @en Clear check
* @cn 清除校验
* @en Clear verification. Not passing names will clear the verification of all fields.
* @cn 清除校验, 不传 names 会清空所有字段的校验
*/
clearValidate: () => void
clearValidate: (names?: string[]) => void
/**
* @en Submit Form, withValidate: Whether to verify
* @cn 提交表单, withValidate: 是否校验
Expand Down

0 comments on commit 63bc43f

Please sign in to comment.