@homebound/form-state 2.26.5 → 2.26.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fields/listField.js +1 -1
- package/dist/formState.test.js +13 -0
- package/package.json +1 -1
package/dist/fields/listField.js
CHANGED
|
@@ -173,7 +173,7 @@ function newListFieldState(parentCopy, parentInstance, parentState, key, rules,
|
|
|
173
173
|
// passing us cloned rows from the parentCopy, but `getOrCreateChildState` will
|
|
174
174
|
// use the `copyMap` to recover the non-cloned rows, to avoid promoting the clone
|
|
175
175
|
// into a real row.
|
|
176
|
-
parentInstance[key] = values.map((child) => getOrCreateChildState(child, opts).value);
|
|
176
|
+
parentInstance[key] = (values !== null && values !== void 0 ? values : []).map((child) => getOrCreateChildState(child, opts).value);
|
|
177
177
|
// Make sure to tick first so that `setOriginalValue` sees the latest `rows`
|
|
178
178
|
_tick.value++;
|
|
179
179
|
// Reset originalCopy so that our dirty checks have the right # of rows.
|
package/dist/formState.test.js
CHANGED
|
@@ -152,6 +152,19 @@ describe("formState", () => {
|
|
|
152
152
|
expect(state.books.rows[2].value === b1).toEqual(true);
|
|
153
153
|
expect(ticks).toEqual(3);
|
|
154
154
|
});
|
|
155
|
+
it("list value can refresh on undefined", () => {
|
|
156
|
+
// Given a list field that is currently []
|
|
157
|
+
const a1 = { firstName: "a1", books: [] };
|
|
158
|
+
const state = createAuthorInputState(a1);
|
|
159
|
+
// When we refresh it with undefined
|
|
160
|
+
state.set({ books: undefined }, { refreshing: true });
|
|
161
|
+
// Then it doesn't blow up, and stays []
|
|
162
|
+
expect(state.books.value).toEqual([]);
|
|
163
|
+
expect(state.value).toEqual({ firstName: "a1", books: [] });
|
|
164
|
+
// And it's not considered changed
|
|
165
|
+
expect(state.books.dirty).toBe(false);
|
|
166
|
+
expect(state.books.originalValue).toEqual([]);
|
|
167
|
+
});
|
|
155
168
|
it("list value can observe changes", () => {
|
|
156
169
|
const b1 = { title: "t1" };
|
|
157
170
|
const a1 = { firstName: "a1", books: [b1] };
|