📽 feature: validate function to include formValues (#9079)
type FormValues = {
number1: number;
number2: number;
};
// Making exported validate function isolated for validation
export function validateNumber(_: number, formValus: FormValues) {
return formValus.number1 + formValus.number2 === 3;
}
export default function App() {
const { register, handleSubmit } = useForm({
defaultValues: {
number1: 0,
number2: 0
}
});
return (
<form onSubmit={handleSubmit((data) => console.log(data))}>
<input
type="number"
{...register("number1", {
validate: validateNumber,
valueAsNumber: true
})}
/>
<input
type="number"
{...register("number2", {
validate: validateNumber,
valueAsNumber: true
})}
/>
<button>submit</button>
</form>
);
}
🛤️ keep track of traversed types to avoid self-referencing while constructing paths for a type (#9540)
🏋🏻♀️ reduced code with unset by weight reduce of 1% (#9575)
📔 fix warning for setValue test case
🪜 Improve handleSubmit
function
thanks to @SimplyLinn & @Mini-ghost