Showing / Hiding properties based on the value of ...
# help-with-umbraco
a
I'm trying to re-create a notifications area from a previous version of umbraco and wondering if there's a better way. Here's the setup: There is a doc type for "announcements". The announcement has an "audience" field, which can be one of several pre-defined categories, or it could be "targeted". If you pick targeted, you have to fill in a bunch of extra fields about who exactly you are targeting (eg. department, seniority, gender, etc) If you pick on of the pre-defined categories, you have to leave all the extra targeting fields empty. In the previous version of this, all the targeting fields were marked as optional, and we had a custom validator that forced you to fill them in or leave them blank according to what you picked. I'd really like to make the UI a bit cleaner if possible this time round though, and actually HIDE the fields if you choose one of the pre-defined audiences. Anyone have any experience doing something like this?
d
If you are on a version below V14 you can have a look at this package : https://marketplace.umbraco.com/package/our.umbraco.conditionaldisplayers
k
Why not make the Audience field an inline blocklist with exactly 1 item, which is a Target Audience block (with buncha fields) or a Audience Category block (with just a dropdown). I think you could tweak the editing UI to make this not-clumsy. And you'd have never have redundant fields in the data, hidden or not.
d
@kdx-perbol that is a option too.
a
@Kaspar Boel Kjeldsen I had considered that as an option - just trying to see if there was another way. @dawoe21 Thanks for the package link - I'll go have a look at the code and see how it was implemented.
20 Views