#State and Inertia.js integration

44 messages · Page 1 of 1 (latest)

thin ibex
#

I want to be able to store and then restore the full form state, with inertia. Is that possible, and if so, how do I get the full form state and how can I restore full form state?

lofty goblet
#

we're planning on adding a persister to help with tackling this. If you could elaborate on how inertia saves and restores data, it could help for drafting the API for it

thin ibex
lofty goblet
thin ibex
# lofty goblet to receive form state, try an attached event listener in `listeners`. to set for...

You mean setting the defaultValues to the state and listening and storing state like this?

listeners: {
            onChange: ({ formApi }) => {
                const currentValues = {
                    username: formApi.getFieldValue('username') as string,
                    notifications_enabled: formApi.getFieldValue('notifications_enabled') as boolean,
                };
                router.remember(currentValues, FORM_STATE_KEY);
            },

Is there not a more efficient way to retrieve the entire state and restore it without having to go over each field and use defaultValues?

lofty goblet
#
listeners: {
  onChange: ({ formApi }) => {
    router.remember(formApi.state.values, FORM_STATE_KEY)
  }
}
thin ibex
lofty goblet
#

stackblitz, codesandbox, something of that type?

thin ibex
lofty goblet
#

that's a start, but I meant where I can insert that component to have the type errors that you're experiencing as well

#

this is just one file of the full stack, no?

thin ibex
thin ibex
thin ibex
lofty goblet
#

sure, I'll give it a try later this evening

thin ibex
lofty goblet
#

we'll keep it in mind! Also thanks in advance for the guide

thin ibex
lofty goblet
#

I‘ll try to start it up this evening or tomorrow. The guide looks to be straightforward!

thin ibex
lofty goblet
thin ibex
# lofty goblet good catch with the docs! I'll answer the question on the PR for clarity, but I'...

Thank you so much!

I hate to be this guy, but the Svelte docs are lacking a bit. Many pages are missing, for example Listeners page, Custom Errors and more. It would be great if they could be updated to match the React docs at least for all core features. If I find the time, I will maybe open a PR to improve the docs as it took me quite a while of reading React docs to get my Svelte code working.

lofty goblet
#

absolutely. Svelte and lit are quite behind, and vue / solid / angular are also missing some docs.

Frankly, there‘s still documentation to be made for React too … it‘s quite a lot.

Our PRs are open though, so even if it‘s just to fix that erroneous condition in the svelte example, feel free to open one!

I‘ll see how much time I have the coming month, but I plan to test out frameworks apart from just React so I can expand the docs myself

thin ibex
#

It would be nice and very helpful. As the docs is pretty much the only source of truth and also needed for AI as it is a newer library. I'll see what I can do in terms of PRs. My to-do list is also quite endless but I am sure I can make some time.

lofty goblet
#

Well, I didn't get around to it yet! Hopefully I'll have proper time this evening.

thin ibex
lofty goblet
#

in the root route, this is what I see.

Running the upstream v5.x-form-test branch and following the step-by-step

#

doesn't seem like it reports any errors to the terminal. The routes in web.php don't lead to anywhere though

#

AAAH, wrong port facepalm I went to 5173 instead of 8000. Nevermind, continuing the test!

lofty goblet
thin ibex
lofty goblet
#

it looks like the main issue with using the form state instead of only values is that it can't be cloned

#

which I'm not sure why. First time I encounter that error

#

this error in particular

#

there's some SO questions addressing it, but they're all about vue and not svelte

thin ibex
thin ibex