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

Validation for field with a name contains dot will fail #220

Open
winston0410 opened this issue Feb 6, 2023 · 3 comments
Open

Validation for field with a name contains dot will fail #220

winston0410 opened this issue Feb 6, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@winston0410
Copy link
Contributor

Describe the bug

Validation for field with a name contains dot will fail

I notice that @felte/validator-zod will parse the name of field automatically, which resulted in unexpected validation result.

For example, having a field called traits.email, I expect this is the structure of the $error

  <!-- {"traits.email": null} -->

But this is what I am getting now

  <!-- {"traits":{"email":null}} -->

This make all validations fail and the form cannot be submitted.

Which package/s are you using?

felte (Svelte), @felte/validator-zod

Environment

	"@felte/reporter-svelte": "^1.1.5",
	"@felte/validator-zod": "^1.0.13",
	"felte": "^1.2.7",
	"zod": "^3.20.2"

To reproduce

Check https://github.com/winston0410/felte-zod-repo/blob/c39d253e5b6bd8db5b3e4fcc60a3213dbfac15d7/src/routes/%2Bpage.svelte#L24-L31

Small reproduction example

https://github.com/winston0410/felte-zod-repo

Screenshots

No response

Additional context

No response

@winston0410 winston0410 added the bug Something isn't working label Feb 6, 2023
@winston0410
Copy link
Contributor Author

digging into this deepr myself, I realise that the issue was the main package of felte parsed the string key into an object. To workaround this issue right now, adjusting the schema is the simplist fix

@winston0410
Copy link
Contributor Author

@pablo-abc just wondering is this behavior of felte expected?

@pablo-abc
Copy link
Owner

pablo-abc commented Feb 18, 2023

Yep, this is expected behaviour. Felte (and specially its validators) are made to handle what will eventually be a JSON payload. Dot notation is used in this case to represent nested objects. Validation in this case should be done by validating a nested object itself, not a property with a . in its name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants