Skip to content

Commit b5a0fc5

Browse files
committed
feat: form - updates option to hide fields, widgets
fix #137 Signed-off-by: Pamfilos Fokianos <pamfilosf@gmail.com>
1 parent 7d6f76b commit b5a0fc5

3 files changed

Lines changed: 21 additions & 16 deletions

File tree

src/admin/utils/fieldTypes.jsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export const common = {
6464
title: "Collapsible",
6565
type: "boolean",
6666
},
67+
hidden: {
68+
type: "boolean",
69+
title: "Hidden",
70+
tooltip:
71+
"When enabled, this field will not be visible in the form, but data can exist and be validated",
72+
},
6773
},
6874
// Using dependencies here instead of if-then-else simplifies reusing the common properties
6975
dependencies: {
@@ -126,7 +132,10 @@ export const common = {
126132
collapsible: {
127133
"ui:widget": "switch",
128134
},
129-
"ui:order": ["showAsModal", "modal", "collapsible", "*"],
135+
hidden: {
136+
"ui:widget": "switch",
137+
},
138+
"ui:order": ["showAsModal", "modal", "hidden", "collapsible", "*"],
130139
"ui:padding": 0,
131140
"ui:label": false,
132141
},
@@ -174,9 +183,7 @@ const collections = {
174183
...common.optionsSchema,
175184
},
176185
},
177-
optionsSchemaUiSchema: {
178-
...common.optionsSchemaUiSchema,
179-
},
186+
optionsSchemaUiSchema: common.optionsSchemaUiSchema,
180187
optionsUiSchema: {
181188
type: "object",
182189
title: "UI Schema",
@@ -188,11 +195,6 @@ const collections = {
188195
common.optionsUiSchema.properties["ui:options"].dependencies,
189196
properties: {
190197
...common.optionsUiSchema.properties["ui:options"].properties,
191-
hidden: {
192-
type: "boolean",
193-
title: "Do you want this field to be hidden?",
194-
description: "If yes, this field will not be visible in the form",
195-
},
196198
},
197199
},
198200
"ui:label": common.optionsUiSchema.properties["ui:label"],

src/forms/templates/Field/FieldTemplate.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const FieldTemplate = ({
4343
} = formContext;
4444

4545
const { token } = theme.useToken();
46+
const { ["ui:options"]: uiOptions = {} } = uiSchema;
4647

4748
if (hidden) {
4849
return <div className="field-hidden">{children}</div>;
@@ -53,8 +54,6 @@ const FieldTemplate = ({
5354
<div key={`field-${id}-error-${error}`}>{error}</div>
5455
));
5556

56-
const { ["ui:options"]: uiOptions = {} } = uiSchema;
57-
5857
const shouldShowAsModal = uiOptions?.showAsModal === true;
5958
const collapsible = uiOptions?.collapsible === true;
6059

@@ -124,6 +123,7 @@ const FieldTemplate = ({
124123
label &&
125124
FieldHeaderWithProps
126125
}
126+
hidden={hidden || uiOptions?.hidden}
127127
labelCol={labelCol}
128128
required={required}
129129
style={{ ...wrapperStyle, ...stylePatches(id, patches, token) }}

src/forms/templates/utils/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const _checkIfHidden = (name, uiSchema) => {
22
return (
3-
uiSchema &&
4-
uiSchema[name] &&
5-
uiSchema[name]["ui:options"] &&
6-
uiSchema[name]["ui:options"].hidden
3+
(uiSchema &&
4+
uiSchema[name] &&
5+
uiSchema[name]["ui:options"] &&
6+
uiSchema[name]["ui:options"].hidden) ||
7+
(uiSchema && uiSchema["ui:options"] && uiSchema["ui:options"].hidden)
78
);
89
};
910

@@ -20,7 +21,9 @@ export const _filterTabs = (tabs, options, properties) => {
2021
return options.tabs;
2122
}
2223
return properties.filter(
23-
(item) => !_checkIfHidden(item.name) && item.name !== "analysis_reuse_mode",
24+
(item) =>
25+
!_checkIfHidden(item.name, item?.content?.props?.uiSchema) &&
26+
item.name !== "analysis_reuse_mode",
2427
);
2528
};
2629

0 commit comments

Comments
 (0)