Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$constraints empty in Client-Side-Mode #475

Closed
philippone opened this issue Sep 2, 2024 · 1 comment
Closed

$constraints empty in Client-Side-Mode #475

philippone opened this issue Sep 2, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@philippone
Copy link

philippone commented Sep 2, 2024

Description
I'm using Superforms with Valibot in SPA Mode but $constraints are empty ({}).

The form validation seems to be working and displays all errors correctly but when I want to use $constraints of a field it is empty.

const _userSchema = v.object({
	text: v.pipe(v.string(), v.minLength(2), v.maxLength(10))
})

const formData = {
	text: 'hallo'
}

const { form, errors, message, constraints, enhance } = superForm(
    formData,
    {
      SPA: true,
      validators: valibot(_userSchema),
	validationMethod: 'oninput'
    }
  );

$: console.log({$constraints}); // empty {}

I tried it with a Zod Schema but it's also empty.

When using the official tutorial (from docs) that is creating the form on the server then$constraints its populated correctly.

MRE

Valibot:

https://www.sveltelab.dev/9mybppcxpyhugni?files=.%2Fsrc%2Froutes%2F%2Bpage.svelte

Zod:
https://www.sveltelab.dev/9mybppcxpyhugni?files=.%2Fsrc%2Froutes%2Fzod%2F%2Bpage.svelte

@philippone philippone added the bug Something isn't working label Sep 2, 2024
@ciscoheat
Copy link
Owner

Constraints are only available on the client when you have used superValidate. The "undocumented" way you're using superForm` now (send an object to it directly) won't be able to figure them out automatically.

To get constraints even in SPA mode, you need to use a +page.ts file: https://superforms.rocks/concepts/spa#using-pagets-instead-of-pageserverts

@ciscoheat ciscoheat added documentation Improvements or additions to documentation and removed bug Something isn't working labels Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants