Skip to content

Commit 608655b

Browse files
committed
fix(renderer): use initialValues instead of initialValue
1 parent 3cfbaf6 commit 608655b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/react-form-renderer/src/use-field-api/use-field-api.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import componentTypes from '../component-types';
88
import { prepareArrayValidator, getValidate } from './validator-helpers';
99
import composeValidators from './compose-validators';
1010
import isEqual from 'lodash/isEqual';
11+
import get from 'lodash/get';
1112

1213
const calculateInitialValue = (props) => {
1314
if (Object.prototype.hasOwnProperty.call(props, 'initialValue') && props.dataType) {
@@ -88,6 +89,10 @@ const useFieldApi = ({ name, resolveProps, skipRegistration = false, ...props })
8889
const { validatorMapper, formOptions } = useContext(RendererContext);
8990
const [warning, setWarning] = useState();
9091

92+
// if there is field initial value, we have to check form initialValues
93+
// initialValues should have higher priority
94+
const formInitialValue = Object.prototype.hasOwnProperty.call(props, 'initialValue') ? get(formOptions.initialValues, name) : undefined;
95+
9196
const resolvedProps = resolveProps ? resolveProps(props, createFieldProps(name, formOptions), formOptions) || {} : {};
9297

9398
const combinedProps = { ...props, ...resolvedProps };
@@ -112,7 +117,7 @@ const useFieldApi = ({ name, resolveProps, skipRegistration = false, ...props })
112117
...(stateValidate ? { validate: stateValidate } : {}),
113118
};
114119

115-
const field = useField(name, enhancedProps);
120+
const field = useField(name, { ...enhancedProps, ...(typeof formInitialValue !== 'undefined' && { initialValue: formInitialValue }) });
116121

117122
/** Reinitilize type */
118123
useEffect(() => {

0 commit comments

Comments
 (0)