Skip to content

Commit

Permalink
chore: use the same disabled api from switchField
Browse files Browse the repository at this point in the history
  • Loading branch information
luizakp committed Mar 14, 2024
1 parent 5b87ed7 commit 2c2c68e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
7 changes: 6 additions & 1 deletion src/components/FormBuilder/fields/InputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export const InputField = withConditional<InputFieldProps>(
e.stopPropagation();
};

const disabled =
typeof field.disabled === "function"
? field.disabled(form.getValues())
: field.disabled;

return (
<FormField
control={form.control}
Expand All @@ -56,7 +61,7 @@ export const InputField = withConditional<InputFieldProps>(
<Input
placeholder={field.placeholder}
{...formField}
disabled={field.disabled ? (field.disabled as boolean) : false}
disabled={disabled}
type={field.mode}
onWheel={(event) =>
field.mode === "number" &&
Expand Down
79 changes: 43 additions & 36 deletions src/components/FormBuilder/fields/selects/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,48 @@ export interface SelectFieldProps extends BaseField {
}

export const SelectField = withConditional<SelectFieldProps>(
({ form, field }) => (
<FormField
control={form.control}
name={field.name}
rules={field.required ? { required: true } : undefined}
render={({ field: formField }) => (
<FormItem className="w-full">
<FormLabel tooltip={field.tooltip}>{field.label}</FormLabel>
<FormDescription>{field.description}</FormDescription>
<Select.SelectRoot
onValueChange={formField.onChange}
defaultValue={String(formField.value)}
name={field.name}
disabled={field.disabled ? (field.disabled as boolean) : false}
>
<FormControl>
<Select.SelectTrigger className="h-10 w-full rounded-md border dark:border-2 shadow-none">
<Select.SelectValue placeholder={field.placeholder} />
</Select.SelectTrigger>
</FormControl>
<Select.SelectContent className="z-[10000]">
{field.options.map((option) => (
<Select.SelectItem
key={String(option.value)}
value={String(option.value)}
>
{option.label}
</Select.SelectItem>
))}
</Select.SelectContent>
</Select.SelectRoot>
({ form, field }) => {
const disabled =
typeof field.disabled === "function"
? field.disabled(form.getValues())
: field.disabled;

<FormMessage />
</FormItem>
)}
/>
)
return (
<FormField
control={form.control}
name={field.name}
rules={field.required ? { required: true } : undefined}
render={({ field: formField }) => (
<FormItem className="w-full">
<FormLabel tooltip={field.tooltip}>{field.label}</FormLabel>
<FormDescription>{field.description}</FormDescription>
<Select.SelectRoot
onValueChange={formField.onChange}
defaultValue={String(formField.value)}
name={field.name}
disabled={disabled}
>
<FormControl>
<Select.SelectTrigger className="h-10 w-full rounded-md border dark:border-2 shadow-none">
<Select.SelectValue placeholder={field.placeholder} />
</Select.SelectTrigger>
</FormControl>
<Select.SelectContent className="z-[10000]">
{field.options.map((option) => (
<Select.SelectItem
key={String(option.value)}
value={String(option.value)}
>
{option.label}
</Select.SelectItem>
))}
</Select.SelectContent>
</Select.SelectRoot>

<FormMessage />
</FormItem>
)}
/>
);
}
);

0 comments on commit 2c2c68e

Please sign in to comment.