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

is there a way to define the condition to enable / disable fields inside the meta #165

Open
deekshithmr95 opened this issue Mar 2, 2023 · 1 comment

Comments

@deekshithmr95
Copy link

is there a way to define the condition to enable/disable fields inside the meta, For example

const meta = [
{
key: 'favoriteFruit',
label: 'Favorite Fruit',
widget: 'radio-group',
options: ['Apple', 'Orange', 'Other'],
initialValue: 'Apple',
},
{
key: 'disableInput',
label: 'Sample Input to disable if the user selects Orange,
widget: 'input',
},
]

I want to disable the input field if the user selects the Orange from the radio group

@berakoc
Copy link

berakoc commented Oct 18, 2023

Yes. You can definitely do that. But this issue is not about antd-form-builder, it's about Antd Form. You have to listen the changes in 'favoriteFruit' field and then conditionally remove the other field. I leave an example below.

const FruitForm = () => {
  const [form] = Form.useForm();
  // Only usable when [email protected] or above
  const favoriteFruit = Form.useWatch('favoriteFruit', form);
  const meta = [
    {
      key: 'favoriteFruit',
      label: 'Favorite Fruit',
      widget: 'radio-group',
      options: ['Apple', 'Orange', 'Other'],
      initialValue: 'Apple',
    },
    favoriteFruit !== 'orange' && {
      key: 'disableInput',
      label: 'Sample Input to disable if the user selects Orange',
      widget: 'input',
    },
  ].filter(Boolean);

  return 'Some JSX';
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants