I have an input and a checkbox. You can write in the input and submit which will submit correct data. You can disable the input by clicking on the checkbox and it will submit null value which is what I want. But when you fill the input and disable the input with the checkbox and submit, it will submit the current value but I want it to submit null since it is disabled. I'm using react hook form with yup.
Here is an example: https://codesandbox.io/s/zen-snow-rtc9b0?file=/src/App.js
I have tried to use setValue from react hook form(shown in the sandbox) when you check the checkbox it will set the value to null but when you check the checkbox again, the current value will be removed but I want to have the previous value.
const onSubmitHandler = ({ checkbox, number }) => { if (checkbox) { let newData = { checkbox, number: null }; console.log(newData); } else { console.log(checkbox, number); } };