Replies: 1 comment
-
Thanks for opening this discussion, it will be very helpful to improve the docs ! In the meantime, I think you'll find it instructive to look at the implementation https://github.com/Hebilicious/form-actions-nuxt/blob/main/packages/form-actions-nuxt/src/runtime/composables/useFormAction.ts You are right, submitForm doesn't let you access the response, because it needs to handle potential redirects and errors, which is handled by the composable : https://github.com/Hebilicious/form-actions-nuxt/blob/075420a66afc4204c2150705ac706837c8dc2e4c/packages/form-actions-nuxt/src/runtime/composables/useFormAction.ts#L26C1-L46C4 We could provide a way for users to disable that handling, but I don't think there's a good use case for that. You should get everything that you need in The value should be updated yes, if it's not, that's a bug, please share a repo/stackblitz or open an issue. |
Beta Was this translation helpful? Give feedback.
-
(I was originally thinking of creating an issue, but found out it could've been my misunderstanding of the API. Changing it as a discussion)
This is what I want to achieve with
v-enhance
:run()
handler.Here's the original code which I was doing something wrong:
1. Odd form submission behaviorI was observing weird behaviors of having form submitting twice, and sometime once.. and I think I now know why.
Somehow I had the idea that
cancel()
is cancelling the whole thing, andsubmitForm()
is "continuing the submission". So I was thinking 'in order to not to cancel, and keep on submitting', I need to not call thecancel()
method but call thesubmitForm()
.And now, I think I have another idea, which is
cancel
cancels the submission, which means you need to call submit yourself.submitForm
is sending a form submission, regardless of whether there previously were any. So If I had notcancel
'ed it, there would be two requests.So maybe a better code would be like:
2.
submitForm
return valueAnother issue -- and this is the reason I am posting in spite of the embarrassing mistake -- is that I want to take the result of the response, and do some stuff here. However I cannot take the response and use it, because
submitForm
returnsundefined
. Is the data value inconst { data } = await useFormAction(...)
being updated? It doesn't seem so.Currently I am calling another
useLoader()
afterawait submitForm()
, and this looks weird.It is documented that the type of
submitForm
is() => Promise<void>
, so I would not get any returned value. This would be more of a feature request.It there another way to achieve this in enhanced mode?
Beta Was this translation helpful? Give feedback.
All reactions