Skip to content

Commit abcb16a

Browse files
authored
fix(core): allow optional text fields in dynamic form (#2782)
1 parent 9cc6786 commit abcb16a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

.changeset/pink-zoos-attend.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
"@bigcommerce/catalyst-core": patch
3+
---
4+
5+
Add missing check for optional text field in `core/vibes/soul/form/dynamic-form/schema.ts`.
6+
7+
## Migration
8+
9+
Add `if (field.required !== true) fieldSchema = fieldSchema.optional();` to `text` case in `core/vibes/soul/form/dynamic-form/schema.ts`:
10+
11+
```typescript
12+
case 'text':
13+
fieldSchema = z.string();
14+
15+
if (field.pattern != null) {
16+
fieldSchema = fieldSchema.regex(new RegExp(field.pattern), {
17+
message: 'Invalid format.',
18+
});
19+
}
20+
21+
if (field.required !== true) fieldSchema = fieldSchema.optional();
22+
23+
break;
24+
```

core/vibes/soul/form/dynamic-form/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ function getFieldSchema(field: Field) {
179179
});
180180
}
181181

182+
if (field.required !== true) fieldSchema = fieldSchema.optional();
183+
182184
break;
183185

184186
case 'password':

0 commit comments

Comments
 (0)