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

Would an API like this for conditional fields be possible? #126

Open
austincondiff opened this issue Jan 7, 2021 · 1 comment
Open

Would an API like this for conditional fields be possible? #126

austincondiff opened this issue Jan 7, 2021 · 1 comment

Comments

@austincondiff
Copy link

If we could inject data into the fields array like this, I believe this would be a much simpler API.

const fields = ({ data }) => [
  {
    name: 'useReadme',
    label: 'Use ReadMe',
    component: 'toggle',
  },
  ...(data.useReadme
    ? [
        {
          name: 'title',
          label: 'Title',
          component: 'text',
        },
        {
          name: 'body',
          label: 'Body',
          component: 'markdown',
        },
      ]
    : []
  ),
]
const fields = ({ data }) => [
  {
    label: 'Internal',
    name: 'internal',
    description: 'Set to false if you want link to another website',
    component: 'toggle',
  },
  ...(data.internal
    ? [
        {
          label: 'Slug',
          name: 'slug',
          component: 'text',
        },
      ]
    : [
        {
          label: 'Link',
          name: 'link',
          component: 'text',
        },
      ]
  ),
]

Thoughts?

@austincondiff austincondiff changed the title Would an API like this for conditional be possible? Would an API like this for conditional fields be possible? Jan 7, 2021
@oskareke
Copy link

oskareke commented Jun 7, 2021

This would be very helpful not just for conditional fields but also to simplify building more advanced form controls using remote data.

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