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

Field conditions on related entries #1267

Open
wesort opened this issue Nov 19, 2024 · 1 comment
Open

Field conditions on related entries #1267

wesort opened this issue Nov 19, 2024 · 1 comment

Comments

@wesort
Copy link

wesort commented Nov 19, 2024

Following on from this Discord thread, I found it unintuitive how to conditionally show/hide fields based on the value of an Entries field. I tried the docs for Conditional Fields, but it doesn't include this.

Context

  • A collection called Archive has an entries field called Archive type which allows users to select 1 (max items) entry from another collection called Archive type
  • Elsewhere on the Archive blueprint, I need to show/hide fields based on what the user choose in Archive type.
    • eg: If they choose Video, then show the field Video meta info
    • eg: If they choose Photo, then hide the field Video meta info

Condition that does not work

  • My instinct was to set the condition to equals video, but this doesn't work.
    image
  • I also stabbed around trying various combinations using contains, ===, prepending with $root and collection::archive_type::

Solution / Workaround

  • get the ID of the Archive type entry of Video and use contains or contains_any (comma separating the IDs)
if_any:
  archive_type: 'contains_any 7d9c28d8-dfb6-4d73-973f-8936f818109f, 484a539d-640d-4b86-b102-108a1cfbe777'
  • The above will show the Video meta info field if a user chooses Video or Interview for the Archive type.

I could raise a PR for the docs if someone feels this would be useful. Being able to select the relevant entries in the Conditions UI would be even better, but I'm not sure how many people using this approach.

@daun
Copy link

daun commented Nov 19, 2024

I was thinking this might be a good use case for a custom field condition to query against the slug and makes this a bit more readable, but that probably doesn't work since the data inside the conditions would be just the id, right? So no way to query the slug without major contortions.

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