diff --git a/src/field.ts b/src/field.ts index 6ccfec5..d6efe43 100644 --- a/src/field.ts +++ b/src/field.ts @@ -180,7 +180,7 @@ export class FieldImplementation }; updateOriginalValue(value: Partial): void { - if (typeof value === 'object') { + if (value && typeof value === 'object') { this.#originalValue = { ...this.#originalValue, ...value }; Object.keys(value).forEach((key) => { const field = this.fields[key]; diff --git a/src/form.spec.ts b/src/form.spec.ts index 0a1f2fa..b6bccd1 100644 --- a/src/form.spec.ts +++ b/src/form.spec.ts @@ -535,6 +535,12 @@ describe(Form, () => { expect(form.fields.name.value).toEqual('Jorge'); }); + it('allows updating the underlying model even with null values', async () => { + const form = createForm({ value: { name: undefined } }); + form.updateOriginalModel({ name: null }); // null counts as an object, check that it doesn't break + expect(form.model.name).toBeNull(); + }); + it('does not change the dirty status when changing the underlying model', async () => { const form = createForm({ value: { name: 'Klaus' } }); form.fields.name.onChange('Claudia');