diff --git a/packages/core/src/utils.js b/packages/core/src/utils.js index 6034a81b94..6780c8a717 100644 --- a/packages/core/src/utils.js +++ b/packages/core/src/utils.js @@ -301,7 +301,7 @@ export function getDefaultFormState( if (isObject(formData) || Array.isArray(formData)) { return mergeDefaultsWithFormData(defaults, formData); } - if (formData === 0 || formData === false) { + if (formData === 0 || formData === false || formData === "") { return formData; } return formData || defaults; diff --git a/packages/core/test/StringField_test.js b/packages/core/test/StringField_test.js index 6f4c56716d..89e30cca21 100644 --- a/packages/core/test/StringField_test.js +++ b/packages/core/test/StringField_test.js @@ -200,6 +200,21 @@ describe("StringField", () => { expect(comp.state.formData).eql("default"); }); + it("should handle an empty string change event with defaults set", () => { + const { comp, node } = createFormComponent({ + schema: { + type: "string", + default: "a", + }, + }); + + Simulate.change(node.querySelector("input"), { + target: { value: "" }, + }); + + expect(comp.state.formData).eql(undefined); + }); + it("should fill field with data", () => { const { node } = createFormComponent({ schema: {