Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(form): fix reset form error #2760

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/form/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export default mixins(classPrefixMixins).extend({
},
];
},
formDataKeys(): string[] {
uyarn marked this conversation as resolved.
Show resolved Hide resolved
return keys(this.data);
},
controlledComponents(): string[] {
let fields = FORM_CONTROL_COMPONENTS;
if (this.formControlledComponents?.length) {
Expand Down Expand Up @@ -165,9 +168,10 @@ export default mixins(classPrefixMixins).extend({
e?.preventDefault();
e?.stopPropagation();
}
const fields = keys(this.data);
this.children
.filter((child) => this.isFunction(child.resetField) && this.needValidate(String(child.name), fields))
.filter(
(child) => this.isFunction(child.resetField) && this.needValidate(String(child.name), this.formDataKeys),
)
.forEach((child) => child.resetField(this.resetType || 'initial'));
emitEvent<Parameters<TdFormProps['onReset']>>(this, 'reset', { e });
},
Expand All @@ -183,7 +187,9 @@ export default mixins(classPrefixMixins).extend({
// exposure function, If there is no reset button in form, this function can be used
reset<T = FormData>(params: FormResetParams<T> = {}) {
this.children
.filter((child) => this.isFunction(child.resetField))
.filter(
(child) => this.isFunction(child.resetField) && this.needValidate(String(child.name), this.formDataKeys),
)
.forEach((child) => {
const resetType = params.type || this.resetType || 'initial';
if (!params.fields || (params.fields && params.fields.includes(child.name as keyof T))) {
Expand Down
Loading