Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-dolls-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@genseki/react": patch
---

[Fix] Error message not show
19 changes: 12 additions & 7 deletions packages/react/src/core/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,34 +733,39 @@ export function fieldToZodScheama<TFieldShape extends FieldShapeBase | FieldShap
case 'time':
case 'password':
case 'media': {
const schema = z.string().min(1, requiredMessage)
const schema = z.string(requiredMessage).min(1, requiredMessage)
return (isRequired ? schema : schema.optional()) as FieldShapeToZodSchema<TFieldShape>
}

case 'email': {
const schema = z.string().min(1, requiredMessage).email('Please enter a valid email address')
const schema = z
.string(requiredMessage)
.min(1, requiredMessage)
.email('Please enter a valid email address')
return (isRequired ? schema : schema.optional()) as FieldShapeToZodSchema<TFieldShape>
}

// string[] input
case 'comboboxText': {
const schema = z.array(z.string()).min(1, requiredMessage)
const schema = z.array(z.string(requiredMessage)).min(1, requiredMessage)
return (isRequired ? schema : schema.optional()) as FieldShapeToZodSchema<TFieldShape>
}

// number input
case 'number':
case 'selectNumber': {
if (isRequired) {
return z.number() as FieldShapeToZodSchema<TFieldShape>
return z.number(requiredMessage) as FieldShapeToZodSchema<TFieldShape>
}
return z.number().optional() as FieldShapeToZodSchema<TFieldShape>
}

// number[] input
case 'comboboxNumber': {
if (isRequired) {
return z.array(z.number()).min(1, requiredMessage) as FieldShapeToZodSchema<TFieldShape>
return z
.array(z.number(requiredMessage))
.min(1, requiredMessage) as FieldShapeToZodSchema<TFieldShape>
}
return z.array(z.number()).optional() as FieldShapeToZodSchema<TFieldShape>
}
Expand All @@ -769,15 +774,15 @@ export function fieldToZodScheama<TFieldShape extends FieldShapeBase | FieldShap
case 'checkbox':
case 'switch': {
if (isRequired) {
return z.boolean() as FieldShapeToZodSchema<TFieldShape>
return z.boolean(requiredMessage) as FieldShapeToZodSchema<TFieldShape>
}
return z.boolean().optional() as FieldShapeToZodSchema<TFieldShape>
}

// date input
case 'date': {
if (isRequired) {
return z.coerce.date() as FieldShapeToZodSchema<TFieldShape>
return z.coerce.date(requiredMessage) as FieldShapeToZodSchema<TFieldShape>
}
return z.coerce.date().optional() as FieldShapeToZodSchema<TFieldShape>
}
Expand Down
Loading