Skip to content

Commit

Permalink
fix auto revalidate
Browse files Browse the repository at this point in the history
  • Loading branch information
pwli0755 committed Aug 28, 2024
1 parent fec2e60 commit 9ba244a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
7 changes: 4 additions & 3 deletions examples/shadcn-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const UserSubscriptionSchema = z.object({
accountType: z.enum(['personal', 'business'], {
required_error: 'You must select an account type',
}),
accountTypes: z.array(z.enum(['personal', 'business'])),
accountTypes: z.array(z.enum(['personal', 'business'])).min(1,'You must select at least one account type'),
interests: z
.array(z.string())
.min(3, 'You must select at least three interest'),
Expand Down Expand Up @@ -180,8 +180,9 @@ function App() {
{ value: 'business2', label: 'Business2' },
]}
/>
{fields.accountTypes.errors && (
<FieldError>{fields.accountTypes.errors}</FieldError>
{fields.accountTypes.allErrors && (
<FieldError>{
Object.values(fields.accountTypes.allErrors).flat()}</FieldError>
)}
</Field>
<Field>
Expand Down
22 changes: 14 additions & 8 deletions examples/shadcn-ui/src/components/conform/ToggleGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,24 @@ export const ToggleGroupConform = ({
onFocus={() => {
toggleGroupRef.current?.focus();
}}
/> : control.value ? (control.value as string[]).map(v => <input
// use the same name as the field, html form will handle the rest
name={meta.name}
/> : <select
multiple
name={meta.name}
className="sr-only"
tabIndex={-1}
value={v}
// we just care the value to be submitted
onChange={() => { }}
ref={control.register}
onFocus={() => {
toggleGroupRef.current?.focus();
}}
/>) : null}
defaultValue={meta.initialValue}
tabIndex={-1}
>
{items.map((item) => (
<option value={item.value} key={item.value}>
{item.label}
</option>
))}
</select>
}

<ToggleGroup
{...props}
Expand Down

0 comments on commit 9ba244a

Please sign in to comment.