Skip to content

Commit

Permalink
Merge pull request #28 from jungsoft/27-setting-defaultvalue-on-formi…
Browse files Browse the repository at this point in the history
…nput-overrides-falsy-values

Fix defaultValue overriding falsy values
  • Loading branch information
pedro-lb authored Jul 7, 2020
2 parents 3914b33 + 2de4f11 commit ea2a9b3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/components/FormInput/FormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ const FormInput = ({
error: formInputError.hasErrors,
};

const inputValue = value ?? defaultValue ?? formInputMeta.initialValue;

const isUntouched = (
(value || defaultValue || formInputMeta.initialValue)
!!inputValue
&& !formInputMeta.touched
&& !isInitializedRef.current
);

if (isUntouched) {
form.setFieldValue(name, value || defaultValue || formInputMeta.initialValue);
form.setFieldValue(name, inputValue);

inputProps.defaultValue = undefined;
isInitializedRef.current = true;
Expand Down

0 comments on commit ea2a9b3

Please sign in to comment.