Hello,
Context : I have a form (useForm) whom validate property is set with a function (it returns a dictionnary of rules, for each field). This function has a varying state and the validate rules depends on it. When I click on a button, I would like to re trigger this function in order to override the validation rules according to the changes of that state.
How could I perform that ?
Code for my form constructor :
const [isSimple, setIsSimple] = useState(simple);
const form = useForm<User>({
initialValues: initialUserForm,
validateInputOnChange: true,
validate: getValidateRules(
t,
isSimple ?? false,
phoneIsValid,
sourceSite,
register ?? false
),
});
And on my button, when I click on it, I want to change the validation rules because "isSimple" changes :
<Button
variant="gradient"
gradient={{ from: "indigo", to: "cyan" }}
onClick={() => {
setIsSimple(false);
}}
>
{t("button.upgradeAccount")}
</Button>
Thanks in advance !