ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Field conditions on related entries

Open wesort opened this issue 1 year ago • 5 comments

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.

wesort avatar Nov 19 '24 15:11 wesort