@nolwenture/formik-jsonschema-form 1.0.0-beta.35 → 1.0.0-beta.36
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/cjs/Form/templates/CollapsibleObjectFieldTemplate/CollapsibleObjectFieldTemplate.js +4 -2
- package/dist/cjs/utils/setTitleValues.js +6 -3
- package/dist/esm/Form/templates/CollapsibleObjectFieldTemplate/CollapsibleObjectFieldTemplate.js +5 -3
- package/dist/esm/utils/setTitleValues.js +6 -3
- package/dist/types/utils/setTitleValues.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/Form/templates/CollapsibleObjectFieldTemplate/CollapsibleObjectFieldTemplate.js
CHANGED
|
@@ -12,8 +12,10 @@ const CollapsibleObjectFieldTemplate = (props) => {
|
|
|
12
12
|
const { Toggle, ChildrenWrapper, RequiredIndicator, Icon, Description, Title, Wrapper, Help, Info, } = (0, styledComponents_1.getComponents)(components);
|
|
13
13
|
const { children, name, uiSchema, ...otherProps } = props;
|
|
14
14
|
const formikCtx = (0, formik_1.useFormikContext)();
|
|
15
|
-
const values = formikCtx.values
|
|
16
|
-
|
|
15
|
+
const values = formikCtx.values
|
|
16
|
+
? formikCtx.values
|
|
17
|
+
: {};
|
|
18
|
+
const title = (0, utils_1.setTitleValues)(name, ((0, utils_1.getTitle)(props) ?? ""), uiSchema?.["ui:options"]?.defaultTitle ?? "", values);
|
|
17
19
|
const description = (0, utils_1.getDescription)(props);
|
|
18
20
|
const { help, info, isCollapsedOnLoad = true, openIcon, collapsedIcon,
|
|
19
21
|
//TODO: This is not right
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setTitleValues = void 0;
|
|
4
4
|
const formik_1 = require("formik");
|
|
5
5
|
// Replaces template string variables with form data for CollapsibleObjectFieldTemplate titles
|
|
6
|
-
const setTitleValues = (name, title, values) => {
|
|
6
|
+
const setTitleValues = (name, title, defaultTitle, values) => {
|
|
7
7
|
const match = name.match(/^([a-zA-Z_$][\w$]*)\[(\d+)\]$/);
|
|
8
8
|
if (match) {
|
|
9
9
|
name = match[1];
|
|
@@ -13,8 +13,11 @@ const setTitleValues = (name, title, values) => {
|
|
|
13
13
|
return title.replace(/\$\{([\w$.]+)\}/g, (match) => {
|
|
14
14
|
const keyMatch = match.match(/^\$\{([\w$.]+)\}$/);
|
|
15
15
|
const key = keyMatch ? keyMatch[1] : "";
|
|
16
|
-
return key === "index"
|
|
17
|
-
|
|
16
|
+
return key === "index"
|
|
17
|
+
? (index + 1).toString()
|
|
18
|
+
: (0, formik_1.getIn)(itemValues, key) !== undefined
|
|
19
|
+
? (0, formik_1.getIn)(itemValues, key)
|
|
20
|
+
: defaultTitle ?? key;
|
|
18
21
|
});
|
|
19
22
|
};
|
|
20
23
|
exports.setTitleValues = setTitleValues;
|
package/dist/esm/Form/templates/CollapsibleObjectFieldTemplate/CollapsibleObjectFieldTemplate.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useFormikContext } from "formik";
|
|
3
3
|
import { useContext, useMemo, useState } from "react";
|
|
4
|
-
import { extractUiSchema, getDescription, getTitle, setTitleValues } from "../../../utils";
|
|
4
|
+
import { extractUiSchema, getDescription, getTitle, setTitleValues, } from "../../../utils";
|
|
5
5
|
import { FormRegistry } from "../../FormRegistry";
|
|
6
6
|
import { getComponents } from "./styledComponents";
|
|
7
7
|
export const CollapsibleObjectFieldTemplate = (props) => {
|
|
@@ -9,8 +9,10 @@ export const CollapsibleObjectFieldTemplate = (props) => {
|
|
|
9
9
|
const { Toggle, ChildrenWrapper, RequiredIndicator, Icon, Description, Title, Wrapper, Help, Info, } = getComponents(components);
|
|
10
10
|
const { children, name, uiSchema, ...otherProps } = props;
|
|
11
11
|
const formikCtx = useFormikContext();
|
|
12
|
-
const values = formikCtx.values
|
|
13
|
-
|
|
12
|
+
const values = formikCtx.values
|
|
13
|
+
? formikCtx.values
|
|
14
|
+
: {};
|
|
15
|
+
const title = setTitleValues(name, (getTitle(props) ?? ""), uiSchema?.["ui:options"]?.defaultTitle ?? "", values);
|
|
14
16
|
const description = getDescription(props);
|
|
15
17
|
const { help, info, isCollapsedOnLoad = true, openIcon, collapsedIcon,
|
|
16
18
|
//TODO: This is not right
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getIn } from "formik";
|
|
2
2
|
// Replaces template string variables with form data for CollapsibleObjectFieldTemplate titles
|
|
3
|
-
export const setTitleValues = (name, title, values) => {
|
|
3
|
+
export const setTitleValues = (name, title, defaultTitle, values) => {
|
|
4
4
|
const match = name.match(/^([a-zA-Z_$][\w$]*)\[(\d+)\]$/);
|
|
5
5
|
if (match) {
|
|
6
6
|
name = match[1];
|
|
@@ -10,7 +10,10 @@ export const setTitleValues = (name, title, values) => {
|
|
|
10
10
|
return title.replace(/\$\{([\w$.]+)\}/g, (match) => {
|
|
11
11
|
const keyMatch = match.match(/^\$\{([\w$.]+)\}$/);
|
|
12
12
|
const key = keyMatch ? keyMatch[1] : "";
|
|
13
|
-
return key === "index"
|
|
14
|
-
|
|
13
|
+
return key === "index"
|
|
14
|
+
? (index + 1).toString()
|
|
15
|
+
: getIn(itemValues, key) !== undefined
|
|
16
|
+
? getIn(itemValues, key)
|
|
17
|
+
: defaultTitle ?? key;
|
|
15
18
|
});
|
|
16
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const setTitleValues: (name: string, title: string, values: Record<string, Array<Record<string, unknown>>>) => string;
|
|
1
|
+
export declare const setTitleValues: (name: string, title: string, defaultTitle: string, values: Record<string, Array<Record<string, unknown>>>) => string;
|
package/package.json
CHANGED