Skip to content

Commit

Permalink
Merge remote-tracking branch 'dpopovms/final-form:main' from final-fo…
Browse files Browse the repository at this point in the history
…rm PR final-form#490; solves issue final-form#489;
  • Loading branch information
Deckstar committed Mar 25, 2024
2 parents ef201af + 012fd2c commit 73ea512
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/final-form/src/FinalForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ function createForm<FormValues extends FormValuesShape = FormValuesShape>(

const state: InternalState<FormValues> = {
subscribers: { index: 0, entries: {} },
fieldSubscribers: {},
fields: {},
fieldSubscribers: Object.create(null),
fields: Object.create(null),
formState: {
asyncErrors: {},
dirtySinceLastSubmit: false,
Expand Down
13 changes: 13 additions & 0 deletions packages/final-form/tests/FinalForm.registerField.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,17 @@ describe("FinalForm.registerField", () => {
expect(typeof spy.mock.calls[0][0].focus).toBe("function");
expect(typeof spy.mock.calls[0][0].change).toBe("function");
});

it("should handle non-prototype fields correctly", () => {
const submitSpy = jest.fn();
const changeSpy = jest.fn();

const form = createForm({ onSubmit: submitSpy });
form.registerField("constructor", changeSpy);

expect(changeSpy).toHaveBeenCalledTimes(1);
form.change("constructor", "bar");
form.submit();
expect(submitSpy).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 73ea512

Please sign in to comment.