Complex Remote Forms #14239
Closed
AndreasHald
started this conversation in
Ideas
Replies: 1 comment
-
New proposal on forms: |
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
Uh oh!
There was an error while loading. Please reload this page.
-
This is a continuation of the discussion in the remote function thread that expanded a bit beyond the scope of the remote functions implementation. So I wanted to lay out my thoughts, and spark a discussion about how complex native forms could be a first class citizen in svelte
Summation
Now that we have remote function forms (they have been out behind an experimental flag for ATLEAST a week, time to expand it). It revives the age old discussion of how do you handle more complex data.
Here it's worth mentioning a few points, svelte also implemented the command especially for this kind of thing and that you can actually do this with the current form implementation, you just have to handle deserialising the
FormData
yourself.But I felt that there was enough positive discussion about other ways svelte could provide a standard for this that I wanted to examine my own thoughts on it a bit.
I think the general consensus from the discussion thread was that you could encode the structure of the object in the path names
So something like
could be turned into
This pattern could also be used to represent deep data
There was also a discussion of how form validation should be handled I believe the prevailing idea was to flatten all paths into a map so taking this html
Could show errors like
My thoughts
I think baking these features into svelte would create the possibility of really exceptional form handling, that could gracefully fallback for non js users, and it would incentivise developers to not always just fallback to
command
I tried implementing some of my thoughts and while you can get pretty far in userland. But it wouldn't create the same level of standard as if svelte advocated directly for the path standard (ruby and PHP have similar patterns). it would also require a few tweaks to the current form implementation because atleast as far as I can tell it's not possible to do some things in userland (yet?).
This is one of the patterns I examined in quite liked
Some of the things that I really like:
Expanding on this pattern the buildForm function could also take a remote query as data instead of a POJO
In this pattern we can populate the form with the query and update the state locally before submitting, taking advantage of the fact that a form submission would could utilise single flight mutations to re-populate.
Other considerations
We could optionally take the schema client side to do validation as you update the form on the client, as to not waste a roundtrip to the server to tell the user a name is required.
We could provide an api to do some validation on the server
Some of the things that makes this tricky to implement in userland
return {_issues: {...}}
and grabbing that result client side. The http code would be wrong however, furthermore AFAIK it's not currently possible to refresh a query conditionally, soawait getPersons().refresh();
would override our local form state because the form technically succeeded.Beta Was this translation helpful? Give feedback.
All reactions