Open vf-unordinary opened 2 months ago
I think in this case the best thing to do is to use createEffect
with our reset
method. https://modularforms.dev/solid/api/reset
Brilliant. It works.
Its a bit counterintuitive to use reset to load data, but nothing a good comment could make it future proof.
Thanks Fabian!
I know. 😐 It makes sense to "reset" the form with new initial values, but I understand that it feels wrong in the first place. Would you choose a different name or just improve the documentation?
In my mind, resetting just restore a previous state of the form. Data loading should define the initial state, until the next submit, which create a new state to rollback.
I've not digged through the code of your brilliant library, so I'm completely ignorant of the process behind: is it difficult to make the createForm
's initiaValues
signal aware? This would make compatible with both createAsync
and createResource
.
Thank you for your feedback and recommendation. I will think about it! I agree that it can improve the DX a lot in these cases.
Hey Fabian! I've found a case when the reset way of filing the form does not work: when a FieldArray is present. It shows the correct number of elements, but no values in them.
I've tried to JSON.stringify the field property returned by the Field component:
this is the content passed with reset {"name":"variants.0.code","error":"","active":true,"touched":false,"dirty":false}
while this is what it pass when using setValues {"name":"variants.0.code","value":"CO400","error":"","active":true,"touched":true,"dirty":true}
I know, and I am sorry. This is a known bug. There should already be an open issue. I hope to find some time one day to fix such problems.
Hi all!
as the title says, is it possible to "watch" createResource/createAsync to load initial values of the form in an async way?
Relying on createEffect to set them using setValues surely works, but for example, in a solid start application interferes with the form submission, firing before the actual form is submitted.
Thanks in advance!