@homebound/form-state 2.2.9 → 2.2.10
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 +1 -1
- package/dist/formState.test.js +34 -0
- package/package.json +1 -1
package/dist/formState.js
CHANGED
|
@@ -350,7 +350,7 @@ function newValueFieldState(parentInstance, parentState, key, rules, isIdKey, is
|
|
|
350
350
|
}
|
|
351
351
|
// If we're being set programmatically, i.e. we don't currently have focus,
|
|
352
352
|
// call blur to trigger any auto-saves.
|
|
353
|
-
if (!this._focused) {
|
|
353
|
+
if (!this._focused && !opts.refreshing && !opts.resetting && this.dirty) {
|
|
354
354
|
this.blur();
|
|
355
355
|
}
|
|
356
356
|
},
|
package/dist/formState.test.js
CHANGED
|
@@ -352,6 +352,10 @@ describe("formState", () => {
|
|
|
352
352
|
a1.firstName.value = "first";
|
|
353
353
|
// Then we call onBlur
|
|
354
354
|
expect(onBlur).toBeCalledTimes(1);
|
|
355
|
+
// And when we set a nested value
|
|
356
|
+
a1.books.rows[0].title.value = "title";
|
|
357
|
+
// Then we called onBlur again
|
|
358
|
+
expect(onBlur).toBeCalledTimes(2);
|
|
355
359
|
});
|
|
356
360
|
it("defers calling onBlur when setting a bound value", () => {
|
|
357
361
|
const onBlur = jest.fn();
|
|
@@ -364,6 +368,36 @@ describe("formState", () => {
|
|
|
364
368
|
// Then we don't call onBlur
|
|
365
369
|
expect(onBlur).toBeCalledTimes(0);
|
|
366
370
|
});
|
|
371
|
+
it("skips onBlur when refreshing", () => {
|
|
372
|
+
const onBlur = jest.fn();
|
|
373
|
+
// Given an author listening for blur
|
|
374
|
+
const a1 = createAuthorInputState({ books: [{}] }, onBlur);
|
|
375
|
+
// When we programmatically set a field that isn't focused
|
|
376
|
+
a1.set({ firstName: "first" }, { refreshing: true });
|
|
377
|
+
// Then we don't call onBlur
|
|
378
|
+
expect(onBlur).toBeCalledTimes(0);
|
|
379
|
+
});
|
|
380
|
+
it("skips onBlur when resetting", () => {
|
|
381
|
+
const onBlur = jest.fn();
|
|
382
|
+
// Given an author listening for blur
|
|
383
|
+
const a1 = createAuthorInputState({ books: [{}] }, onBlur);
|
|
384
|
+
// And we called onBlur once
|
|
385
|
+
a1.set({ firstName: "first" });
|
|
386
|
+
expect(onBlur).toBeCalledTimes(1);
|
|
387
|
+
// When we reset
|
|
388
|
+
a1.reset();
|
|
389
|
+
// We don't call blur again
|
|
390
|
+
expect(onBlur).toBeCalledTimes(1);
|
|
391
|
+
});
|
|
392
|
+
it("skips onBlur when not dirty", () => {
|
|
393
|
+
const onBlur = jest.fn();
|
|
394
|
+
// Given an author listening for blur
|
|
395
|
+
const a1 = createAuthorInputState({ firstName: "first", books: [{}] }, onBlur);
|
|
396
|
+
// When we programmatically set a field to it's existing valued
|
|
397
|
+
a1.firstName.value = "first";
|
|
398
|
+
// Then we don't call onBlur
|
|
399
|
+
expect(onBlur).toBeCalledTimes(0);
|
|
400
|
+
});
|
|
367
401
|
it("knows list of primitives are dirty", () => {
|
|
368
402
|
const a1 = formState_1.createObjectState({ favoriteColors: { type: "value" } }, {});
|
|
369
403
|
expect(a1.favoriteColors.dirty).toBeFalsy();
|