The problem: I'm on the overview and I select a sensor. I edit the name of a sensor. I get send back to overview of all sensors, the name is indeed changed. Then I click on another sensor and without changing anything I save it, then it gets the name of the previous changed sensor. So the field (which is required) is empty. But it still gets through and takes the name of the previous sensor. I have made a video of this problem -> https://www.youtube.com/watch?v=yH-4bW0JEWI.
I tried setting a defaultvalue, but the name of the previous sensor overwrites this if I don't change anything and do click on save. I also tried to reset FormData.name. It does get reset, but when I click on another sensor it magically gets filled with the name of the previous sensor.
So here is my code:
const onSubmit = (formData) => {
data.name = formData.name;
console.log("before formdata: " + formData.name); //when clicked on a new sensor, it gets the formdata from a previous sensor that has been edited
formData.name = "";
console.log("after formdata: " + formData.name); //formdata.name gets resetted
putRequest();
}
function putRequest() {
setIsLoading(true)
axios.put(`api/sensor/${data.sensorId}`, data)
.then(() => {
navigation.push("Overview");
})
and in the return:
<Controller
control={control}
defaultValue={data.name}
render={({onChange}) => (
<TextInput
style={component.textInput}
//defaultValue={data.name}
placeholder={data.name}
autoCapitalize="sentences"
returnKeyType="next"
onChangeText={(e) => onChange(e)}
clearButtonMode="always"
/>
)}
name="name"
rules={{}}//deleted rules for overview
/>
So does anyone know why FormData.Name gets set to the previous sensor when I dont provide a value?
Still have the problem when you assign rules? not null etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With