Skip to content

Commit

Permalink
feat(@uform/core): reset add clearInitialValue (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Jan 20, 2020
1 parent 1aa77db commit 02e715c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 9 deletions.
21 changes: 17 additions & 4 deletions packages/antd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3031,10 +3031,14 @@ interface IFormActions {
* Reset form
*/
reset(options?: {
// Forced to empty
forceClear?: boolean // Forced check
validate?: boolean // Reset range for batch or precise control of the field to be reset
//force clear
forceClear?: boolean
//validate in reset
validate?: boolean
//select field in reset
selector?: FormPathPattern
//clear initialValue
clearInitialValue?:boolean
}): Promise<void | IFormValidateResult>
/*
* Validation form, throw IFormValidateResult when validation fails
Expand Down Expand Up @@ -3134,7 +3138,16 @@ interface IFormAsyncActions {
/*
* Reset form
*/
reset(options?: IFormResetOptions): Promise<void>
reset(options?: {
//force clear
forceClear?: boolean
//validate in reset
validate?: boolean
//select field to reset
selector?: FormPathPattern
//clear initialValue
clearInitialValue?:boolean
}): Promise<void>
/*
* Get status changes, mainly used to determine which states in the current life cycle have changed in the form lifecycle hook.
* For example, hasChanged(state,'value.aa')
Expand Down
13 changes: 12 additions & 1 deletion packages/antd/README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -3082,6 +3082,8 @@ interface IFormActions {
validate?: boolean
//重置范围,用于批量或者精确控制要重置的字段
selector?: FormPathPattern
//是否清空默认值
clearInitialValue?:boolean
}): Promise<void | IFormValidateResult>
/*
Expand Down Expand Up @@ -3252,7 +3254,16 @@ interface IFormAsyncActions {
/*
* 重置表单
*/
reset(options?: IFormResetOptions): Promise<void>
reset(options?: {
//强制清空
forceClear?: boolean
//强制校验
validate?: boolean
//重置范围,用于批量或者精确控制要重置的字段
selector?: FormPathPattern
//是否清空默认值
clearInitialValue?:boolean
}): Promise<void>
/*
* 获取状态变化情况,主要用于在表单生命周期钩子内判断当前生命周期中有哪些状态发生了变化,
* 比如hasChanged(state,'value.aa')
Expand Down
1 change: 1 addition & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ interface IForm {
forceClear?: boolean // Forced check
validate?: boolean // Reset range for batch or precise control of the field to be reset
selector?: FormPathPattern
clearInitialValue?: boolean //Clear initialValue
}): Promise<void | IFormValidateResult>
/*
* Validation form, throw IFormValidateResult when validation fails
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,8 @@ export function createForm<FieldProps, VirtualFieldProps>(
async function reset({
selector = '*',
forceClear = false,
validate = true
validate = true,
clearInitialValue = false
}: IFormResetOptions = {}): Promise<void | IFormValidateResult> {
graph.eachChildren('', selector, field => {
field.setState((state: IFieldState<FieldProps>) => {
Expand All @@ -847,6 +848,9 @@ export function createForm<FieldProps, VirtualFieldProps>(
state.ruleWarnings = []
state.effectErrors = []
state.effectWarnings = []
if (clearInitialValue) {
state.initialValue = undefined
}
// forceClear仅对设置initialValues的情况下有意义
if (forceClear || !isValid(state.initialValue)) {
if (isArr(state.value)) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export interface IFormSubmitResult {
export interface IFormResetOptions {
forceClear?: boolean
validate?: boolean
clearInitialValue?: boolean
selector?: FormPathPattern
}

Expand Down
14 changes: 13 additions & 1 deletion packages/next/README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -3028,6 +3028,8 @@ interface IFormActions {
validate?: boolean
//重置范围,用于批量或者精确控制要重置的字段
selector?: FormPathPattern
//是否清空默认值
clearInitialValue?:boolean
}): Promise<void | IFormValidateResult>
/*
Expand Down Expand Up @@ -3149,7 +3151,16 @@ interface IFormAsyncActions {
/*
* 重置表单
*/
reset(options?: IFormResetOptions): Promise<void>
reset(options?: {
//强制清空
forceClear?: boolean
//强制校验
validate?: boolean
//重置范围,用于批量或者精确控制要重置的字段
selector?: FormPathPattern
//是否清空默认值
clearInitialValue?:boolean
}): Promise<void>
/*
* 获取状态变化情况,主要用于在表单生命周期钩子内判断当前生命周期中有哪些状态发生了变化,
* 比如hasChanged(state,'value.aa')
Expand Down Expand Up @@ -3219,6 +3230,7 @@ interface IFormAsyncActions {
}
```


#### ButtonProps

```typescript
Expand Down
15 changes: 14 additions & 1 deletion packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2562,6 +2562,8 @@ interface IForm {
     validate?: boolean
     // Reset range for batch or precise control of the field to be reset
     selector?: FormPathPattern
//clear initialValue
clearInitialValue?:boolean
   }): Promise<void | IFormValidateResult>
   
   /*
Expand Down Expand Up @@ -2796,6 +2798,8 @@ interface IFormActions {
forceClear?: boolean // Forced check
validate?: boolean // Reset range for batch or precise control of the field to be reset
selector?: FormPathPattern
//clear initialValue
clearInitialValue?: boolean
}): Promise<void | IFormValidateResult>
/*
* Validation form, throw IFormValidateResult when validation fails
Expand Down Expand Up @@ -2892,7 +2896,16 @@ interface IFormAsyncActions {
/*
* Reset form
*/
reset(options?: IFormResetOptions): Promise<void>
reset(options?: {
//force clear
forceClear?: boolean
//validate in reset
validate?: boolean
//select field to reset
selector?: FormPathPattern
//clear initialValue
clearInitialValue?:boolean
}): Promise<void>
/*
* Get status changes, mainly used to determine which states in the current life cycle have changed in the form lifecycle hook.
* For example, hasChanged(state,'value.aa')
Expand Down
15 changes: 14 additions & 1 deletion packages/react/README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -2573,6 +2573,8 @@ interface IForm {
validate?: boolean
//重置范围,用于批量或者精确控制要重置的字段
selector?: FormPathPattern
//是否清空默认值
clearInitialValue?:boolean
}): Promise<void | IFormValidateResult>
/*
Expand Down Expand Up @@ -2806,6 +2808,8 @@ interface IFormActions {
validate?: boolean
//重置范围,用于批量或者精确控制要重置的字段
selector?: FormPathPattern
//是否清空默认值
clearInitialValue?:boolean
}): Promise<void | IFormValidateResult>
/*
Expand Down Expand Up @@ -2924,7 +2928,16 @@ interface IFormAsyncActions {
/*
* 重置表单
*/
reset(options?: IFormResetOptions): Promise<void>
reset(options?: {
//强制清空
forceClear?: boolean
//强制校验
validate?: boolean
//重置范围,用于批量或者精确控制要重置的字段
selector?: FormPathPattern
//是否清空默认值
clearInitialValue?:boolean
}): Promise<void>
/*
* 获取状态变化情况,主要用于在表单生命周期钩子内判断当前生命周期中有哪些状态发生了变化,
* 比如hasChanged(state,'value.aa')
Expand Down

0 comments on commit 02e715c

Please sign in to comment.