Async field validation
A field check requires asynchronous work.
Conform · Function
conformZodMessage provides special messages that control how Conform handles Zod validation. It supports skipping a check while keeping the previous result or marking validation undefined so Conform falls back to the server.
The conformZodMessage object provides special Zod messages that control whether Conform keeps a prior validation result or falls back to server validation. Assign these constants as validation messages when implementing async or conditionally deferred checks.
conformZodMessage.VALIDATION_SKIPPED
conformZodMessage.VALIDATION_UNDEFINEDAn object containing the special Zod validation messages VALIDATION_SKIPPED and VALIDATION_UNDEFINED.
import { z } from 'zod';
import { conformZodMessage, parseWithZod } from '@conform-to/zod';
const schema = z.object({
email: z.string().email().refine(
async (email) => email !== 'taken@example.com',
{ message: conformZodMessage.VALIDATION_UNDEFINED },
),
});
const result = parseWithZod(new FormData(), { schema });
console.log(result);Use the special undefined-validation message on an async check so Conform defers that validation to the server.
A field check requires asynchronous work.
A current validation should not replace an existing outcome.
The client cannot determine a validation result and needs authoritative server handling.
conformZodMessage is a set of special messages for controlling Conform's validation behavior. Its documented constants include VALIDATION_SKIPPED and VALIDATION_UNDEFINED.
Follow-up: How would you defer an async field check? Return VALIDATION_UNDEFINED as the check's validation message so Conform falls back to server validation.
VALIDATION_SKIPPED indicates that the current validation should be skipped. Conform uses the previous validation result instead.
Follow-up: When is this useful? It is useful when the current validation should not replace an already available result, such as when avoiding unnecessary schema work.
VALIDATION_UNDEFINED marks validation as not defined for the current situation. Conform then falls back to server validation rather than treating the result as a normal validation outcome.
Follow-up: How does this support async validation? An async-dependent check can emit this marker, allowing server-side validation to perform the authoritative check.
parseWithZod@conform-to/zodVALIDATION_SKIPPEDVALIDATION_UNDEFINED