felte icon indicating copy to clipboard operation
felte copied to clipboard

setErrors not working with server side errors.

Open inder2303 opened this issue 3 years ago • 1 comments

I am trying feltejs for the first time. all is working. but I am not able to figure out how setErrros work with server-side errors.

const { form, errors, setFields, setErrors } = createForm({ onSubmit: async (values) => { console.log('values', values); postData(values); } // extend: validator({ schema }) });

post Request

const postData = (values) => { axios .post('plans', JSON.stringify(values), { headers: { 'Content-Type': 'application/json' } }) .then((response) => { console.log('response', response); if (response.status == 201) { navigate('/a/plans/'); } }) .catch((error) => { const httpError = HandleHttpErrors(error); setErrors(httpError); console.log('httpErrors', httpErrors().title); }); } };

can anyone please explain what I am doing wrong?

inder2303 avatar Sep 05 '22 11:09 inder2303

You don't need to use setErrors to handle server side errors. You can use the onError callback on the configuration object.

pablo-abc avatar Sep 06 '22 18:09 pablo-abc

thank you

inder2303 avatar Dec 22 '22 15:12 inder2303