Replies: 1 comment
-
I'm still wondering if I'm doing things wrong 🙄 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'd like to handle field errors when submitting a form using createServerAction$. I understand I can throw a ResponseError but I can't find in the doc how to use it.
The ultimate goal is to highlight the fields with errors and provide a useful description (validation done with zod). Coming from Remix, I'm looking for something similar to useActionData 🙈
In this example https://start.solidjs.com/core-concepts/actions#using-forms-to-submit-data, we throw a
new Error("invalid username")
. How can we industrialise this for a more complex form when using zod validation? Can I pass an object/json instead?I was thinking about this for the meantime:
But the createEffect only prints undefined. Pretty sure I'm doing something wrong.. 😅
Digging further, I feel I should do that:
And do this:
What I'm struggling to find is how to retrieve the fieldErrors so I can provide fine-grained error explanation (field by field). Actually, it is available in
add.error.fieldErrors
but it is not typed. Is there a way to type it?Going forward, I was wondering how I can simplify this:
I ended up with this:
Not quire sure why errors if not reactive without using signal. But it works ^^
In the end, I have this
It is very boilerplate but digging a bit further, it seems you can provide back the formData in FormError so you can feed the value back in your form (useful when JS is off).
But either I'm doing something wrong, either this should be simplified in some ways because that's heavy 😓
I would really appreciate any feedback on how you do that.
Beta Was this translation helpful? Give feedback.
All reactions