@nolwenture/formik-jsonschema-form 1.0.0-beta.47 → 1.0.0-beta.49

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.
@@ -5,19 +5,26 @@ const react_1 = require("react");
5
5
  const formik_1 = require("formik");
6
6
  const utils_1 = require("../../utils");
7
7
  const useSetDefault = (props) => {
8
- if (!props.name) {
8
+ if (!props.name)
9
9
  return;
10
- }
11
- const [{ value }, _, { setValue }] = (0, formik_1.useField)(props.name);
10
+ const [{ value }, , { setValue }] = (0, formik_1.useField)(props.name);
12
11
  (0, react_1.useEffect)(() => {
13
- if (!value) {
14
- if (props.schema.default) {
15
- setValue(props.schema.default);
12
+ let newValue = value;
13
+ if (value === "now" && props.schema.format === "date") {
14
+ const today = new Date().toISOString().split("T")[0];
15
+ newValue = today;
16
+ }
17
+ if (!newValue) {
18
+ if (props.schema.default !== undefined) {
19
+ newValue = props.schema.default;
16
20
  }
17
21
  else if (props.forceDefaultValue) {
18
- setValue((0, utils_1.getDefaultValueForType)(props.schema.type));
22
+ newValue = (0, utils_1.getDefaultValueForType)(props.schema.type);
19
23
  }
20
24
  }
21
- }, []);
25
+ if (newValue && newValue !== value) {
26
+ setValue(newValue);
27
+ }
28
+ }, [value, props.schema.default, props.forceDefaultValue]);
22
29
  };
23
30
  exports.useSetDefault = useSetDefault;
@@ -11,18 +11,6 @@ exports.ObjectFieldTemplateWrapper = styled_components_1.default.div `
11
11
  &[data-fjsf-level="1"] {
12
12
  margin-bottom: ${(props) => props.theme.spacing.xxl};
13
13
  }
14
-
15
- &[data-fjsf-level="2"] {
16
- -webkit-column-break-inside: avoid;
17
- page-break-inside: avoid;
18
- break-inside: avoid;
19
- }
20
-
21
- &[data-fjsf-level="3"] {
22
- -webkit-column-break-inside: avoid;
23
- page-break-inside: avoid;
24
- break-inside: avoid;
25
- }
26
14
 
27
15
  `;
28
16
  exports.ObjectFieldTemplateTitle = styled_components_1.default.div `
@@ -2,18 +2,25 @@ import { useEffect } from "react";
2
2
  import { useField } from "formik";
3
3
  import { getDefaultValueForType } from "../../utils";
4
4
  export const useSetDefault = (props) => {
5
- if (!props.name) {
5
+ if (!props.name)
6
6
  return;
7
- }
8
- const [{ value }, _, { setValue }] = useField(props.name);
7
+ const [{ value }, , { setValue }] = useField(props.name);
9
8
  useEffect(() => {
10
- if (!value) {
11
- if (props.schema.default) {
12
- setValue(props.schema.default);
9
+ let newValue = value;
10
+ if (value === "now" && props.schema.format === "date") {
11
+ const today = new Date().toISOString().split("T")[0];
12
+ newValue = today;
13
+ }
14
+ if (!newValue) {
15
+ if (props.schema.default !== undefined) {
16
+ newValue = props.schema.default;
13
17
  }
14
18
  else if (props.forceDefaultValue) {
15
- setValue(getDefaultValueForType(props.schema.type));
19
+ newValue = getDefaultValueForType(props.schema.type);
16
20
  }
17
21
  }
18
- }, []);
22
+ if (newValue && newValue !== value) {
23
+ setValue(newValue);
24
+ }
25
+ }, [value, props.schema.default, props.forceDefaultValue]);
19
26
  };
@@ -4,18 +4,6 @@ export const ObjectFieldTemplateWrapper = styled.div `
4
4
  &[data-fjsf-level="1"] {
5
5
  margin-bottom: ${(props) => props.theme.spacing.xxl};
6
6
  }
7
-
8
- &[data-fjsf-level="2"] {
9
- -webkit-column-break-inside: avoid;
10
- page-break-inside: avoid;
11
- break-inside: avoid;
12
- }
13
-
14
- &[data-fjsf-level="3"] {
15
- -webkit-column-break-inside: avoid;
16
- page-break-inside: avoid;
17
- break-inside: avoid;
18
- }
19
7
 
20
8
  `;
21
9
  export const ObjectFieldTemplateTitle = styled.div `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolwenture/formik-jsonschema-form",
3
- "version": "1.0.0-beta.47",
3
+ "version": "1.0.0-beta.49",
4
4
  "description": "Formik form generation from json schema",
5
5
  "author": "anttivikman <antti.vikman@nolwenture.com>",
6
6
  "contributors": [
@@ -124,4 +124,4 @@
124
124
  "last 1 safari version"
125
125
  ]
126
126
  }
127
- }
127
+ }