Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disable property to input and select field #34

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/components/FormBuilder/fields/InputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const InputField = withConditional<InputFieldProps>(
<Input
placeholder={field.placeholder}
{...formField}
disabled={field.disabled ? (field.disabled as boolean) : false}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it not boolean by default in the type? 😬 it should be disabled?: boolean. this could be written as field.disabled ?? false

Copy link
Contributor Author

@luizakp luizakp Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now

disabled?: boolean | ((data: FieldValues) => boolean);

and with this I get

Type 'boolean | ((data: FieldValues) => boolean)' is not assignable to type 'boolean | undefined'.
  Type '(data: FieldValues) => boolean' is not assignable to type 'boolean | undefined'.ts(2322)

Saw we do this on SwitchField

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

type={field.mode}
onWheel={(event) =>
field.mode === "number" &&
Expand Down
1 change: 1 addition & 0 deletions src/components/FormBuilder/fields/selects/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const SelectField = withConditional<SelectFieldProps>(
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">
Expand Down