ciscoheat / sveltekit-superforms

Making SvelteKit forms a pleasure to use!
https://superforms.rocks
MIT License
2.23k stars 66 forks source link

ActionData didn't return a Validation object. Make sure you return { form } from form actions. #2

Closed ElijahJohnson5 closed 1 year ago

ElijahJohnson5 commented 1 year ago

I am returning a form from my action like so

 const { locals } = event;

  const form = await superValidate(event, schema);

  console.log(form);

  if (!form.valid) {
    return fail(400, { form });
  }

with the schema:

const schema = z.object({
  firstName: z.string(),
  lastName: z.string(),
  password: z.string(),
  email: z.string().email()
});

However I get the error: ActionData didn't return a Validation object. Make sure you return { form } from form actions. unless I change the fail line to return fail(400, { form: { ...form, success: false } })

I am using the form in my page like so const { form, errors } = superForm(data.form);

Am I missing that I should have to manually set success because the docs don't show that. I am using sveltekit 1.8.3

hmiiro commented 1 year ago

Okay, let me be aware of this too as i try this out. Have you tried when the data you're returning is a list of objects say array of users?

On Thu, 23 Feb 2023, 10:48 am Elijah Johnson, @.***> wrote:

I am returning a form from my action like so

const { locals } = event;

const form = await superValidate(event, schema);

console.log(form);

if (!form.valid) { return fail(400, { form }); }

with the schema:

const schema = z.object({ firstName: z.string(), lastName: z.string(), password: z.string(), email: z.string().email() });

However I get the error: ActionData didn't return a Validation object. Make sure you return { form } from form actions. unless I change the fail line to return fail(400, { form: { ...form, success: false } })

Am I missing that I should have to manually set success because the docs don't show that.

— Reply to this email directly, view it on GitHub https://github.com/ciscoheat/sveltekit-superforms/issues/2, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIMV5QLBE5BVKVHWD5MXARDWY4I4XANCNFSM6AAAAAAVFIZKKY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ciscoheat commented 1 year ago

Hi, I have just updated the library to version 0.5.4, can you try it out and see if it's fixed? success should not exist anymore.

Also, are you doing a return { form } at the end of the successful branch of the function?

ciscoheat commented 1 year ago

Found the error now, it should be fixed in version 0.5.5, released in a few moments.

ciscoheat commented 1 year ago

Updated now! Now you should be able to remove success, thank you for finding this. :)

ElijahJohnson5 commented 1 year ago

Just tried out the updated version, now its getting mad about Cannot find module 'sveltekit-flash-message/client'. When I install that package manually the issue seems to be fixed!

ciscoheat commented 1 year ago

Yes, there are some issues right now with integrating the library with sveltekit-flash-message, which are almost impossible to debug without publishing to npm and see what happens. I'll release a new 0.5.x version later when this is fixed.

ElijahJohnson5 commented 1 year ago

Thanks! You can close this issue then!

ciscoheat commented 1 year ago

Ok, just released version 0.5.8, which seems to work fine!