Skip to content

Commit

Permalink
Change TextInput to not initially show errors on an empty form
Browse files Browse the repository at this point in the history
  • Loading branch information
indigane committed Jul 26, 2024
1 parent 1f30db4 commit 8a189f4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions frontend/src/common/components/forms/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ const TextInput = ({name, label = "", required, invalid, ...rest}: FormInputProp

const {
register,
formState: {errors},
formState: {errors, dirtyFields},
} = formObject;
const formText = register(name, {required: required});
const fieldError = dotted(errors, formText.name);
const isFieldDirty = dirtyFields[name] ?? false;
const hasValue = formObject.getValues(formText.name) !== "";
const shouldShowError = isFieldDirty || hasValue;
const fieldError = shouldShowError ? dotted(errors, formText.name) : undefined;

return (
<div className={`input-field input-field--text ${required ? "input-field--required" : ""}`}>
Expand Down

0 comments on commit 8a189f4

Please sign in to comment.