Skip to content

How to use readSelection? #278

Answered by mskocik
galaczi asked this question in Q&A
Jan 24, 2025 · 2 comments · 8 replies

You must be logged in to vote

Starting a new thread which fixes all your problems.

Fix schema in +page.server.js

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.

⚠️ If you plan to use superForm with resetForm: false you need this additional code to bypass superform's setting value to null and to correct value again:

<script> section:

let cached…

Replies: 2 comments 8 replies

You must be logged in to vote
4 replies
@galaczi

@mskocik

@galaczi

@mskocik

You must be logged in to vote
4 replies
@mskocik

@galaczi

@galaczi

@mskocik

Answer selected by galaczi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants