Skip to content

Commit 0312449

Browse files
author
Jon Waldstein
committed
fix: allow nullable types with format in ajv
1 parent 0dcc2a6 commit 0312449

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Admin/ajv.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ function transformFormDataForValidation(data: any, schema: JSONSchemaType<any>):
379379

380380
// Only process fields that are present in the form OR are required
381381
if (propSchema && (isFieldPresent || isRequired)) {
382+
// Coerce empty string to null for nullable fields to avoid format/type conflicts (e.g., uri, email)
383+
if (Array.isArray(propSchema.type) && propSchema.type.includes('null')) {
384+
if (['', null, undefined].includes(result[key])) {
385+
result[key] = null;
386+
return; // Skip further processing for this field
387+
}
388+
}
382389
// Handle number types
383390
if (propSchema.type === 'number' && typeof value === 'string') {
384391
// Convert string to number

0 commit comments

Comments
 (0)