Skip to content

Commit 5d5dd50

Browse files
committed
Adde clearedValue override from field.
1 parent 896dd8f commit 5d5dd50

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

packages/pf4-component-mapper/src/tests/field-array/__snapshots__/field-array.test.js.snap

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ exports[`FieldArray should render array field correctly 1`] = `
2424
buttonClassName=""
2525
buttonsLabels={Object {}}
2626
clearOnUnmount={false}
27-
clearedValue="foo"
2827
disableSubmit={Array []}
2928
formFieldsMapper={
3029
Object {
@@ -136,7 +135,7 @@ exports[`FieldArray should render array field correctly 1`] = `
136135
"blur": [Function],
137136
"change": [Function],
138137
"clearOnUnmount": false,
139-
"clearedValue": "foo",
138+
"clearedValue": undefined,
140139
"concat": [Function],
141140
"destroyOnUnregister": false,
142141
"focus": [Function],
@@ -198,7 +197,7 @@ exports[`FieldArray should render array field correctly 1`] = `
198197
"blur": [Function],
199198
"change": [Function],
200199
"clearOnUnmount": false,
201-
"clearedValue": "foo",
200+
"clearedValue": undefined,
202201
"concat": [Function],
203202
"destroyOnUnregister": false,
204203
"focus": [Function],
@@ -254,7 +253,7 @@ exports[`FieldArray should render array field correctly 1`] = `
254253
"blur": [Function],
255254
"change": [Function],
256255
"clearOnUnmount": false,
257-
"clearedValue": "foo",
256+
"clearedValue": undefined,
258257
"concat": [Function],
259258
"destroyOnUnregister": false,
260259
"focus": [Function],
@@ -311,7 +310,7 @@ exports[`FieldArray should render array field correctly 1`] = `
311310
"blur": [Function],
312311
"change": [Function],
313312
"clearOnUnmount": false,
314-
"clearedValue": "foo",
313+
"clearedValue": undefined,
315314
"concat": [Function],
316315
"destroyOnUnregister": false,
317316
"focus": [Function],
@@ -405,7 +404,7 @@ exports[`FieldArray should render array field correctly 1`] = `
405404
"blur": [Function],
406405
"change": [Function],
407406
"clearOnUnmount": false,
408-
"clearedValue": "foo",
407+
"clearedValue": undefined,
409408
"concat": [Function],
410409
"destroyOnUnregister": false,
411410
"focus": [Function],

packages/react-form-renderer/demo/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const App = () => (
2525
<div style={{ padding: 20 }}>
2626
<FormRenderer
2727
initialValues={{
28-
text_box_1: 'hue'
28+
text_box_1: 'hue',
29+
text_box_3: 'initial'
2930
}}
3031
clearedValue={'bla'}
3132
layoutMapper={layoutMapper}

packages/react-form-renderer/demo/sandbox.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const output = {
3636
label: 'Text Box 3',
3737
isRequired: true,
3838
component: components.TEXT_FIELD,
39+
clearedValue: 'override',
3940
validate: [
4041
{ type: validators.MIN_LENGTH, treshold: 12, message: 'bar' },
4142
],

packages/react-form-renderer/src/form-renderer/field-provider.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ class FieldProvider extends Component{
2121

2222
render(){
2323
const { clearOnUnmount, component, render, dataType, children, ...props } = this.props;
24+
const fieldClearedValue = props.hasOwnProperty('clearedValue') ? props.clearedValue : props.formOptions.clearedValue;
25+
const { clearedValue, ...fieldProps } = props;
2426
if (component) {
2527
const FieldComponent = component;
26-
return <Field { ...props } render={ ({ input: { onChange, ...input }, ...fieldsProps }) => (
28+
return <Field { ...fieldProps } render={ ({ input: { onChange, ...input }, ...fieldsProps }) => (
2729
<FieldComponent
2830
{ ...fieldsProps }
2931
input={{
@@ -33,7 +35,7 @@ class FieldProvider extends Component{
3335
...fieldsProps.meta,
3436
dataType,
3537
onChange,
36-
clearedValue: this.props.formOptions.clearedValue,
38+
clearedValue: fieldClearedValue,
3739
}, ...args);
3840
},
3941
}}
@@ -42,7 +44,7 @@ class FieldProvider extends Component{
4244
}
4345

4446
if (render) {
45-
return <Field { ...props } render={ ({ input: { onChange, ...input }, ...fieldsProps }) => render({
47+
return <Field { ...fieldProps } render={ ({ input: { onChange, ...input }, ...fieldsProps }) => render({
4648
...fieldsProps,
4749
input: {
4850
...input,
@@ -51,15 +53,15 @@ class FieldProvider extends Component{
5153
...fieldsProps.meta,
5254
dataType,
5355
onChange,
54-
clearedValue: this.props.formOptions.clearedValue,
56+
clearedValue: fieldClearedValue,
5557
}, ...args),
5658
},
5759
}) } />;
5860
}
5961

6062
const ChildComponent = children;
6163
return (
62-
<Field { ...props }>
64+
<Field { ...fieldProps }>
6365
{ ({ input: { onChange, ...input }, ...fieldsProps }) =>
6466
Children.only(
6567
<ChildComponent
@@ -69,7 +71,7 @@ class FieldProvider extends Component{
6971
...fieldsProps.meta,
7072
dataType,
7173
onChange,
72-
clearedValue: this.props.formOptions.clearedValue,
74+
clearedValue: fieldClearedValue,
7375
}, ...args) }}
7476
/>
7577
) }

packages/react-form-renderer/src/tests/form-renderer/enhanced-on-change.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('#enhancedOnChange', () => {
3434
expect(enhancedOnChange({ dataType: 'integer', onChange: value => value, clearedValue }, value)).toEqual([ 1, 2, 3 ]);
3535
});
3636

37-
describe('#setting delete value', () => {
37+
describe('#setting cleared value', () => {
3838
it('should not set any delete value after sending empty value', () => {
3939
const value = undefined;
4040
expect(enhancedOnChange({ onChange: value => value, clearedValue }, value)).toEqual(undefined);

0 commit comments

Comments
 (0)