You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I might be missing something, but it seems like there is not a super-straightforward way (at least not as easy as I'd like) to customize the form data right before submitting, but otherwise keep the submit handler exactly the same as the default behavior of felte.
E.g., if I just want to override a single field value at the time of submission, but otherwise leave the values the same.
I see two DX issues here:
createDefaultSubmitHandler is not exported (from @felte/core) in a way that package consumers can easily access, which makes it hard to write wrappers that do something and then call the default handler, especially since providing a value for onSubmit causes this default handler to no longer be called. Nor does the default handler appear to be exposed in some other way.
onSubmit could made to be more flexible. Or perhaps expose a beforeSubmit or transformBeforeSubmit hook. Right now, you don't get access to the default handler from within it, nor can you do something like return {...values, myField: myOverride} and have that call the default handler
Describe the solution you'd like
I think it might be a good idea to expose createDefaultSubmitHandler regardless if whether a utility callback is added to transform data before submission, as this seems like a useful function to have access to. And in addition, for perhaps the best DX, expose the bound default handler directly through context, in a form that accepts values.
If you had access to it, you could do stuff like this, right?:
createForm({onSubmit(values,context){// do something cool// This would be coolreturncreateDefaultSubmitHandler(context.form)();// even betterreturncontext.defaultSubmitHandler(values);},})
As I'd imagine that mutating data right before submission / customizing the submission payload is a somewhat common workflow, it would also be nice to add a specific callback for this. As mentioned, something like beforeSubmit or transformBeforeSubmit that takes values and context, and can return the final values payload to be used for submission.
I've been looking for built-in ways to accomplish this, but so far most of them require far more unnecessary indirection and painful refactoring than I'd like.
Additional context
This has been basically my only pain point with this package - it is overall awesome and very enjoyable to use!
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I might be missing something, but it seems like there is not a super-straightforward way (at least not as easy as I'd like) to customize the form data right before submitting, but otherwise keep the submit handler exactly the same as the default behavior of
felte
.E.g., if I just want to override a single field value at the time of submission, but otherwise leave the values the same.
I see two DX issues here:
createDefaultSubmitHandler
is not exported (from@felte/core
) in a way that package consumers can easily access, which makes it hard to write wrappers that do something and then call the default handler, especially since providing a value foronSubmit
causes this default handler to no longer be called. Nor does the default handler appear to be exposed in some other way.onSubmit
could made to be more flexible. Or perhaps expose abeforeSubmit
ortransformBeforeSubmit
hook. Right now, you don't get access to the default handler from within it, nor can you do something likereturn {...values, myField: myOverride}
and have that call the default handlerDescribe the solution you'd like
I think it might be a good idea to expose
createDefaultSubmitHandler
regardless if whether a utility callback is added to transform data before submission, as this seems like a useful function to have access to. And in addition, for perhaps the best DX, expose the bound default handler directly through context, in a form that accepts values.If you had access to it, you could do stuff like this, right?:
As I'd imagine that mutating data right before submission / customizing the submission payload is a somewhat common workflow, it would also be nice to add a specific callback for this. As mentioned, something like
beforeSubmit
ortransformBeforeSubmit
that takesvalues
andcontext
, and can return the final values payload to be used for submission.E.g.:
Describe alternatives you've considered
I've been looking for built-in ways to accomplish this, but so far most of them require far more unnecessary indirection and painful refactoring than I'd like.
Additional context
This has been basically my only pain point with this package - it is overall awesome and very enjoyable to use!
The text was updated successfully, but these errors were encountered: