Skip to content

Commit 8be3a56

Browse files
committed
feat(common): Added hideField prop to renderer.
1 parent d39c56d commit 8be3a56

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

packages/react-form-renderer/src/form-renderer/render-form.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,39 @@ import Condition from './condition';
77
import { memoize } from '../validators/helpers';
88
import FieldWrapper from './field-wrapper';
99

10+
const FormFieldHideWrapper = ({ hideField, children }) => hideField ? (
11+
<div hidden>{ children }</div>
12+
) : children;
13+
14+
FormFieldHideWrapper.propTypes = {
15+
hideField: PropTypes.bool,
16+
children: PropTypes.oneOfType([ PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]).isRequired,
17+
};
18+
19+
FormFieldHideWrapper.defaultProps = {
20+
hideField: false,
21+
};
22+
1023
const FormConditionWrapper = ({ condition, children }) => (condition ? (
1124
<Condition { ...condition }>
1225
{ children }
1326
</Condition>
1427
) : children);
1528

16-
const renderSingleField = ({ component, condition, ...rest }) => (
29+
const renderSingleField = ({ component, condition, hideField, ...rest }) => (
1730
<Fragment key={ rest.key || rest.name }>
1831
<RendererContext.Consumer>
1932
{ ({ formFieldsMapper, formOptions }) => (
2033
<FormConditionWrapper condition={ condition }>
21-
<FieldWrapper
22-
componentType={ component }
23-
component={ formFieldsMapper[component] }
24-
formOptions={ formOptions }
25-
name={ rest.name || rest.key }
26-
{ ...rest }
27-
/>
34+
<FormFieldHideWrapper hideField={ hideField }>
35+
<FieldWrapper
36+
componentType={ component }
37+
component={ formFieldsMapper[component] }
38+
formOptions={ formOptions }
39+
name={ rest.name || rest.key }
40+
{ ...rest }
41+
/>
42+
</FormFieldHideWrapper>
2843
</FormConditionWrapper>
2944
) }
3045
</RendererContext.Consumer>

0 commit comments

Comments
 (0)