Skip to content

Commit

Permalink
fix(Form): avoid creating fields with empty names
Browse files Browse the repository at this point in the history
  • Loading branch information
tenphi committed Jul 12, 2023
1 parent eea93f2 commit f33bd19
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/forms/Form/ComplexForm.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const CustomSubmitErrorTemplate: StoryFn<typeof Form> = (args) => {
<TextInput />
</Field>
<Submit>Submit</Submit>
{form.submitError ? <Alert>{form.submitError}</Alert> : null}
{form.submitError ? <Alert>{form.submitError as string}</Alert> : null}
</Form>
);
};
Expand Down
1 change: 0 additions & 1 deletion src/components/forms/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ function Form<T extends FieldTypes>(
try {
await form.validateFields();
} catch (e) {
console.error('!', e);
form?.setSubmitting(false);

return;
Expand Down
6 changes: 5 additions & 1 deletion src/components/forms/Form/use-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ export class CubeFormInstance<
}

createField<Name extends keyof T & string>(name: Name, skipRender?: boolean) {
// passing an empty name is incorrect, but we have to return a valid object to avoid inconsistency
if (!name) {
return this._createField(name);
}

if (!this.fields[name]) {
this.fields[name] = this._createField(name);
}
Expand Down Expand Up @@ -369,7 +374,6 @@ export class CubeFormInstance<
name: Name,
data?: Data,
): Data {
console.error('! create field', name, data);
let obj = {
name,
validating: false,
Expand Down

0 comments on commit f33bd19

Please sign in to comment.