Repository navigation
How to update the form when a field update? #574
|
let say i have two fields: const form = useForm({
defaultValues: {
favoriteFood: "",
skip: false,
},
onSubmit: async ({ value }) => {
console.log(value);
},
});
that what i've tried: <form.Field
name="skip"
children={(field) => (
<Checkbox
checked={field.state.value}
name={field.name}
onChange={(e) => {
const isChecked = e.target.checked;
// Try 1: use the form.setFieldValue
field.form.setFieldValue("favoriteFood", isChecked ? "none" : "", { touch: true });
// Try 2: use the form.state.values
field.form.state.values.favoriteFood = isChecked ? "none" : "";
field.handleChange(isChecked)
}}
>
I don't have a favorite food
</Checkbox>
)}
/>I've tried using the any help is appreciated |
Answered by
defaultgnome
Jan 23, 2024
Replies: 1 comment
|
So |
0 replies
Answer selected by
defaultgnome
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So
form.setFieldValue("favoriteFood", "none")is working as expected.in the end it was because i didn't pass the
field.state.valueto the right field of theCheckbox(nextui), in the above code i passed it to thecheckedwhile it should have beenisSelected.