I have an Ant form in a React app, where some fields are required and some not. My problem is that when not required field is empty, backend sends the validation error. My question is, is there a way to NOT TO SEND the value of not required field if there is no value?
Screenshot of the current object that is sent:
My code for form submission:
const submitHandler = async (val: any) => {
setLoading(true);
try {
let res: any = await API.put(`recipients/${pid}`, {
...val,
user_id: loggedInUser.id,
type: type,
});
setLoading(false);
message.success("Benutzer erfolgreich aktualisiert");
setError("");
} catch (error: any) {
setLoading(false);
setError(error?.response.data.message);
message.error(error?.response.data.message);
}
};
