remix-validated-form icon indicating copy to clipboard operation
remix-validated-form copied to clipboard

[Feature]: Suport set field errors programmatically

Open cjoecker opened this issue 1 year ago • 5 comments

What is the new or updated feature that you are suggesting?

I want to set an error on the client side without needing Zod for that.

Something like a setCustomError function in the useFormContext hook will be great. I can then call it like setCustomError("myFieldName", "customError"). We would then need also need a resetCustomError function.

Why should this feature be included?

I have the field A and when it is filled, it calls an external API. Based on the response of the API, I want to be able to set an error to another field B using the result of the API call together with the value of the field B

cjoecker avatar Nov 15 '23 12:11 cjoecker

I agree. eg: check vat number When i use fetcher.load or fetcher.submit to validate the vat input when it loses focus(onBlur), validationError not working because i don't submit the whole form. So i also need one feature like setFieldError

jason-rb2 avatar Dec 07 '23 09:12 jason-rb2

This sounds reasonable to me. Would you mind opening a PR?

airjp73 avatar Dec 07 '23 13:12 airjp73

@airjp73 I will do a PR. Do you have some guidance on how to start the project? I just clone it but I'm not sure how to build the library and test the changes

cjoecker avatar Dec 11 '23 18:12 cjoecker

@airjp73 are you still maintaining the library? I would like to open a PR but I struggled to start the project, know what is the testing approach etc.

cjoecker avatar Mar 28 '24 08:03 cjoecker

Hi! I am but I don't have much time to work on new features. You'll likely need to add a function to the form store and access that in the useFormContext hook. The tests are in the test-app using Cypress -- create a route for the test and then use it in one of the existing test files (or make a new one either is fine here).

The most basic version of this feature probably only touches a couple files.

All the building, testing, etc should be doable from the root of the monrepo. But you can probably run some commands from within specific packages too.

airjp73 avatar Mar 28 '24 13:03 airjp73