Skip to content

Commit

Permalink
Merge pull request #25 from tushar-witbybit/main
Browse files Browse the repository at this point in the history
added onBlur, touched and extrainfo in Field component
  • Loading branch information
nikhilag authored Jan 8, 2024
2 parents b5d7433 + 3fe82a8 commit 2bb1a0f
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@ export const Field = (props: IField) => {
validate,
depFields,
} = props;
const { fieldValue, setFieldValue, error } = useField({
name,
ancestors,
defaultValue,
depFields,
validate: validate
? validate
: (value) => {
if (required && !value) {
return 'Required';
}
return null;
},
});
const { fieldValue, setFieldValue, error, onBlur, touched, extraInfo } =
useField({
name,
ancestors,
defaultValue,
depFields,
validate: validate
? validate
: (value) => {
if (required && !value) {
return 'Required';
}
return null;
},
});

const fieldProps = {
value: fieldValue ?? '',
Expand All @@ -57,7 +58,10 @@ export const Field = (props: IField) => {
setFieldValue(val);
handleChange?.(val);
},
onBlur,
error,
touched,
extraInfo,
};

if (typeof children === 'function') {
Expand Down

0 comments on commit 2bb1a0f

Please sign in to comment.