@homebound/form-state 2.18.0 → 2.18.1

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.
@@ -34,13 +34,17 @@ function newObjectState(config, parentState, parentListState, instance, key, may
34
34
  }
35
35
  return proxy;
36
36
  }
37
+ const objectConfig = config;
37
38
  const fieldStates = Object.entries(config).map(([_key, _config]) => {
38
39
  var _a, _b;
39
40
  const key = _key;
40
41
  const config = _config;
41
42
  let field;
42
43
  if (config.type === "value") {
43
- field = valueField_1.newValueFieldState(instance, getObjectState, key, config.rules || [], config.isIdKey || key === "id", config.isDeleteKey || false, config.isReadOnlyKey || false, config.computed || false, config.readOnly || false, (_a = config.strictOrder) !== null && _a !== void 0 ? _a : true, maybeAutoSave);
44
+ field = valueField_1.newValueFieldState(instance, getObjectState, key, config.rules || [], config.isIdKey ||
45
+ // Default the id key to "id" unless some other field has isIdKey set
46
+ (key === "id" &&
47
+ !Object.entries(objectConfig).some(([other, c]) => other !== key && c.isIdKey)), config.isDeleteKey || false, config.isReadOnlyKey || false, config.computed || false, config.readOnly || false, (_a = config.strictOrder) !== null && _a !== void 0 ? _a : true, maybeAutoSave);
44
48
  }
45
49
  else if (config.type === "list") {
46
50
  field = listField_1.newListFieldState(instance, getObjectState, key, config.rules || [], config, config.config, (_b = config.strictOrder) !== null && _b !== void 0 ? _b : true, maybeAutoSave);
@@ -1390,6 +1390,15 @@ describe("formState", () => {
1390
1390
  `);
1391
1391
  });
1392
1392
  });
1393
+ it("sets id key correctly", () => {
1394
+ // Given an author
1395
+ const a = objectField_1.createObjectState({
1396
+ id: { type: "value" },
1397
+ otherId: { type: "value", isIdKey: true },
1398
+ }, {});
1399
+ expect(a.id._isIdKey).toBe(false);
1400
+ expect(a.otherId._isIdKey).toBe(true);
1401
+ });
1393
1402
  });
1394
1403
  class ObservableObject {
1395
1404
  constructor() {
@@ -9,6 +9,7 @@ export declare enum Color {
9
9
  }
10
10
  export interface AuthorInput {
11
11
  id?: string | null;
12
+ otherId?: string | null;
12
13
  firstName?: string | null;
13
14
  lastName?: string | null;
14
15
  birthday?: Date | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/form-state",
3
- "version": "2.18.0",
3
+ "version": "2.18.1",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",