Closed dsignr closed 3 months ago
Thanks for the question! I think this would fall in the purview of the Svelte adapter rather than the Phoenix server adapter. @tonydangblog by chance have you encountered any challenges with error propagation with Svelte?
I just checked, and everything seems to be working as expected. $form.errors
is populated when using assign_errors
and returning an Inertia response.
@dsignr, I noticed that you are running your console.log
in onMount
, which only runs once and will not run again when the Inertia response returns. You can try adding a $: console.log("$form.errors:", $form.errors);
to your component to see if the errors are populated.
In your template, if you read directly from $form.errors.email
, it should work. Does it show up as undefined
for you?
I just checked, and everything seems to be working as expected.
$form.errors
is populated when usingassign_errors
and returning an Inertia response.@dsignr, I noticed that you are running your
console.log
inonMount
, which only runs once and will not run again when the Inertia response returns. You can try adding a$: console.log("$form.errors:", $form.errors);
to your component to see if the errors are populated.In your template, if you read directly from
$form.errors.email
, it should work. Does it show up asundefined
for you?
Hi Tony, It correctly prints out when I changed the syntax, I guess it was the wrong usage of console.log that caused this. Thanks again!
Hi again, so far the library looks great! Thanks for your hard work. Maybe this is more of information than being an issue itself, but when working with forms, I noticed that the form object isn't being populated with the errors from the backend.
My
product_controller.ex
My frontend looks like this.
Inside
custom_form.svelte
:Inside my
input.svelte
:And finally, inside the
new
template at /storefront/products/new:This setup works perfectly fine. My only query is, the $form object is not populated with the errors, but rather it is being set at
$page.props.errors
. My controller has defined|> assign_errors(changeset)
too as shown above. I checked the documentation at https://inertiajs.com/forms and it seems like from their example, this should work:But, it does not. I can actually see the errors populated inside the data attribute of the div with id
app
too:Is this expected behaviour or am I doing something wrong?
I consulted the readme, the corresponding pull request https://github.com/inertiajs/inertia-phoenix/pull/10 and even the other repo which another commenter mentioned previously at https://github.com/tonydangblog/phoenix-inertia-svelte. It seems to me like the $form object should be populated as per Inertia's own documentation at https://inertiajs.com/forms.
Again, thanks for the wonderful project. Thanks!