@homebound/form-state 2.2.5 → 2.2.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/formState.js CHANGED
@@ -505,6 +505,7 @@ function newListFieldState(parentInstance, parentState, key, rules, listConfig,
505
505
  this.ensureSet();
506
506
  this.value.splice(typeof spliceIndex === "number" ? spliceIndex : this.value.length, 0, childState.value);
507
507
  _tick.value++;
508
+ onBlur();
508
509
  },
509
510
  remove(indexOrValue) {
510
511
  this.ensureSet();
@@ -518,6 +519,7 @@ function newListFieldState(parentInstance, parentState, key, rules, listConfig,
518
519
  }
519
520
  }
520
521
  _tick.value++;
522
+ onBlur();
521
523
  },
522
524
  reset() {
523
525
  if (originalCopy) {
@@ -321,6 +321,16 @@ describe("formState", () => {
321
321
  a1.books.remove(0);
322
322
  expect(a1.dirty).toBeFalsy();
323
323
  });
324
+ it("it calls onBlur when adding or removing to a list", () => {
325
+ const onBlur = jest.fn();
326
+ const a1 = createAuthorInputState({ books: [] }, onBlur);
327
+ expect(a1.books.dirty).toBeFalsy();
328
+ a1.books.add({ title: "t2" });
329
+ expect(a1.books.dirty).toBeTruthy();
330
+ a1.books.remove(0);
331
+ expect(a1.dirty).toBeFalsy();
332
+ expect(onBlur).toBeCalledTimes(2);
333
+ });
324
334
  it("knows list of primitives are dirty", () => {
325
335
  const a1 = formState_1.createObjectState({ favoriteColors: { type: "value" } }, {});
326
336
  expect(a1.favoriteColors.dirty).toBeFalsy();
@@ -1352,7 +1362,7 @@ describe("formState", () => {
1352
1362
  // And the new book is blurred
1353
1363
  rtl_utils_1.click(r.blurNew);
1354
1364
  // Then expect onBlur to be triggered again
1355
- expect(onBlur).toBeCalledTimes(2);
1365
+ expect(onBlur).toBeCalledTimes(3);
1356
1366
  });
1357
1367
  });
1358
1368
  class ObservableObject {
@@ -1386,8 +1396,8 @@ const authorWithBooksConfig = {
1386
1396
  },
1387
1397
  },
1388
1398
  };
1389
- function createAuthorInputState(input) {
1390
- return formState_1.createObjectState(authorWithBooksConfig, input);
1399
+ function createAuthorInputState(input, onBlur) {
1400
+ return formState_1.createObjectState(authorWithBooksConfig, input, { onBlur });
1391
1401
  }
1392
1402
  const authorWithAddressConfig = {
1393
1403
  id: { type: "value" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/form-state",
3
- "version": "2.2.5",
3
+ "version": "2.2.6",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",