@cedarjs/forms 8.0.0-canary.3615 → 8.0.0-canary.3617

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.
@@ -1 +1 @@
1
- {"version":3,"file":"coercion.d.ts","sourceRoot":"","sources":["../src/coercion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,eAAe,EAAY,MAAM,iBAAiB,CAAA;AAE7E;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG;IACrD,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAKD;;;;;;GAMG;AAEH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,WAAW,GAAG,CAAC,GAAG,EAAE,CAAA;AA2KtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,UAAU,gBAAgB;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB;AAED,eAAO,MAAM,WAAW,GACtB,YAAY,sBAAsB,EAClC,yBAAyB,gBAAgB,SAyE1C,CAAA"}
1
+ {"version":3,"file":"coercion.d.ts","sourceRoot":"","sources":["../src/coercion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,eAAe,EAAY,MAAM,iBAAiB,CAAA;AAE7E;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG;IACrD,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAmCD;;;;;;GAMG;AAEH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,WAAW,GAAG,CAAC,GAAG,EAAE,CAAA;AA2KtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,UAAU,gBAAgB;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB;AAED,eAAO,MAAM,WAAW,GACtB,YAAY,sBAAsB,EAClC,yBAAyB,gBAAgB,SAuF1C,CAAA"}
package/dist/coercion.js CHANGED
@@ -1,4 +1,19 @@
1
1
  const isValueEmpty = (val) => val === "";
2
+ const parseDateOnly = (val) => {
3
+ const match = /^(\d{4,})-(\d{2})-(\d{2})$/.exec(val);
4
+ if (!match) {
5
+ return /* @__PURE__ */ new Date(NaN);
6
+ }
7
+ const year = Number(match[1]);
8
+ const month = Number(match[2]) - 1;
9
+ const day = Number(match[3]);
10
+ const date = /* @__PURE__ */ new Date(0);
11
+ date.setUTCFullYear(year, month, day);
12
+ if (year === 0 || date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) {
13
+ return /* @__PURE__ */ new Date(NaN);
14
+ }
15
+ return date;
16
+ };
2
17
  const SET_VALUE_AS_FUNCTIONS = {
3
18
  // valueAsBoolean is commented out as r-h-f does not currently support
4
19
  // setValueAs functionality for checkboxes. May investigate future
@@ -156,16 +171,18 @@ const setCoercion = (validation, { type, name, emptyAs }) => {
156
171
  } else {
157
172
  valueAs = "valueAsString";
158
173
  }
159
- validation.setValueAs = getSetValueAsFn(
174
+ const setValueAs = getSetValueAsFn(
160
175
  valueAs,
161
- // type
162
176
  emptyAs,
163
- // emptyAs
164
177
  validation.required !== void 0 && validation.required !== false,
165
- // required
166
178
  (name || "").endsWith("Id")
167
- // isId
168
179
  );
180
+ if (valueAs === "valueAsDate" && type === "date") {
181
+ delete validation.valueAsDate;
182
+ validation.setValueAs = (val) => typeof val !== "string" || isValueEmpty(val) ? setValueAs?.(val) : parseDateOnly(val);
183
+ } else {
184
+ validation.setValueAs = setValueAs;
185
+ }
169
186
  };
170
187
  export {
171
188
  setCoercion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/forms",
3
- "version": "8.0.0-canary.3615",
3
+ "version": "8.0.0-canary.3617",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -36,7 +36,7 @@
36
36
  "react-hook-form": "7.91.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@cedarjs/framework-tools": "8.0.0-canary.3615",
39
+ "@cedarjs/framework-tools": "8.0.0-canary.3617",
40
40
  "@testing-library/dom": "10.4.2",
41
41
  "@testing-library/jest-dom": "6.9.1",
42
42
  "@testing-library/react": "16.3.3",