-
Briefly, I am trying to wrap Svelecte into a reusable component with Superforms validation. I am doing remote data fetch. The data is in the following format:
SuperForms:
Svelecte:
I am confused about readSelection. Should I listen to changes in $value (coming from superforms on e.g. failed form validation), and set the $value again manually from readSelection? Note that on failed validation only |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
By default, svelecte (single select) expect Your use case: I am not sure... When superforms changes |
Beta Was this translation helpful? Give feedback.
-
Starting a new thread which fixes all your problems. Fix schema in const schema = z.object({
id: z.number().nullable().transform((value, ctx) => {
if (value === null) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
fatal: true,
message: 'ID is required'
});
}
return value;
}),
missing: z.string().nonempty('Missing is required') // so validation fails
}); Now when validation fails on server, item is kept in Svelecte properly.
|
Beta Was this translation helpful? Give feedback.
Starting a new thread which fixes all your problems.
Fix schema in
+page.server.js
Now when validation fails on server, item is kept in Svelecte properly.
superForm
withresetForm: false
you need this additional code to bypass superform's setting value tonull
and to correct value again:<script>
section: