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

Use value from other fields as params in "predefinedTags" fetch #30

Open
MichaelPrecel opened this issue Feb 26, 2024 · 0 comments
Open

Comments

@MichaelPrecel
Copy link

In a regular array field, you can use the value of other fields in the document as params to your request. E.g.,

{
      name: 'tags',
      type: 'array',
      of: [
        {
          type: 'reference',
          to: [{type: 'tag'}],
          weak: true,
          options: {
            filter: ({document}) => {
              return {
                filter: '$section == appliesTo._ref',
                params: {
                  section: document.section?._ref,
                },
              }
            },
          },
        },
      ],
    },

Ideally, with this plugin and a query in the predefinedTags option, you would be able to grab the ({ document }) to use values as params. E.g.,

{
      name: 'tags',
      type: 'tags',
      options: {
        predefinedTags: async ({document}) => await client.fetch(`*[_type == "tagRef" && $section == appliesTo._ref ]{label, value}`, { section: document.section._ref })
        },
      },
    },

Is this possible?

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

1 participant