cannot clearErrors manually before onSubmit #4924
-
|
while setting errors using the can someone please help me with this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
|
could you invoke |
Beta Was this translation helpful? Give feedback.
-
// FormField
export const FormField = props => {
// access context from FormProvider
const { register, clearErrors, formState: { errors } } = useFormContext();
const field_errors = get(errors, props.name);
const handleChange = e => {
console.log('clearing')
clearErrors(e.target.value);
console.log('cleared')
}
return (
<div className="formField-wrapper">
<div className="header">
<label className={`label ${field_errors && 'errors'}`} htmlFor={props.name}>{props.label}</label>
{field_errors && field_errors.type === 'server' &&
<label className="error-msg errors">{field_errors.message}</label>}
</div>
<TextField
register={register}
variant={field_errors ? `${props.variant} errors` : props.variant}
type={props.type}
name={props.name}
defaultValue={props.defaultValue}
value={props.value}
placeholder={props.placeholder}
onChange={handleChange}
maxLength={props.maxLength}
spellCheck={false}
/>
</div>
)
}the event handler is not firing though |
Beta Was this translation helpful? Give feedback.
-
|
Commenting here out of curiosity. Aryan, from what I understand your form has some validation and then something happens and that validation is not needed anymore. So you've got two alternatives:
I'm not a big fan of clearing the errors if you can avoid it, so I've made you an example of the second alternative: Conditional validation + useFormContext. Try using that form with the console open, so you'll see the order of events. Would that alternative work for you? |
Beta Was this translation helpful? Give feedback.

Commenting here out of curiosity. Aryan, from what I understand your form has some validation and then something happens and that validation is not needed anymore.
So you've got two alternatives:
I'm not a big fan of clearing the errors if you can avoid it, so I've made you an example of the second alternative: Conditional validation + useFormContext. Try using that form with the console open, so you'll see the order of events.
Would that alternative work for you?