-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
dataType: 'json'
nested field errors (#159)
Co-authored-by: AdrianGonz97 <[email protected]>
- Loading branch information
1 parent
01e10cb
commit a5966c1
Showing
8 changed files
with
72 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"formsnap": patch | ||
--- | ||
|
||
Fixed a bug where `FieldErrors` wouldn't render errors for nested fields with `dataType: 'json'` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ node_modules | |
/build | ||
/.svelte-kit | ||
/package | ||
/dist | ||
.env | ||
.env.* | ||
!.env.example | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,12 @@ module.exports = { | |
} | ||
] | ||
} | ||
}, | ||
{ | ||
files: ['*.ts', '*.js', '*.svelte'], | ||
rules: { | ||
'no-console': 'error' | ||
} | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<script lang="ts" context="module"> | ||
import { z } from "zod"; | ||
export const formSchema = z.object({ | ||
name: z.string(), | ||
address: z.object({ | ||
country: z.string(), | ||
state: z.string(), | ||
city: z.string(), | ||
streetName: z.string(), | ||
streetNumber: z.string(), | ||
building: z.string(), | ||
apartment: z.string(), | ||
postcode: z.string().min(4).max(10), | ||
}), | ||
}); | ||
export type FormSchema = typeof formSchema; | ||
</script> | ||
|
||
<script lang="ts"> | ||
import SuperDebug, { defaults, superForm } from "sveltekit-superforms"; | ||
import { zod } from "sveltekit-superforms/adapters"; | ||
import { Field, FieldErrors, Control, Label } from "formsnap"; | ||
const form = superForm(defaults(zod(formSchema)), { | ||
SPA: true, | ||
resetForm: false, | ||
validators: zod(formSchema), | ||
dataType: "json", | ||
}); | ||
const { form: formData, enhance, errors } = form; | ||
</script> | ||
|
||
<SuperDebug data={$errors} /> | ||
<form method="POST" use:enhance class="flex flex-col gap-2"> | ||
<Field {form} name="address.postcode"> | ||
<Control let:attrs> | ||
<Label>Postcode</Label> | ||
<input {...attrs} bind:value={$formData.address.postcode} /> | ||
</Control> | ||
<FieldErrors class="text-red-500" /> | ||
</Field> | ||
|
||
<button class="mt-6">Submit</button> | ||
</form> |