Support

Account

Home Forums General Issues Hide values that have been selected in other field

Solving

Hide values that have been selected in other field

  • I have two custom post types, Project and Person.

    Project entries have two custom fields of the Relationship type:

    1. PROJECT LEAD
    2. OTHER RELATED PEOPLE

    Both fields are restricted to the Person post type.

    What I want to do is hide values in each field that have been selected in the other field.

    For example, if Jane is already selected as PROJECT LEAD, I want to remove Jane from the options for OTHER RELATED PEOPLE.

    Is this possible via the available ACF filters?

  • No, it is not possible to do with ACF filters. It would require custom JavaScript be added, and to be honest, I’m not sure it can be done at all using a “Relationship” field, but then I’m not 100% versed in the new ACF JS API https://www.advancedcustomfields.com/resources/javascript-api/

  • Exactly what I’m looking for but for a soccer team 😉 . I’m investigating on this and check some solutions.

    It is not possible on php side because there is no hook when you add/remove an item in one field.

    Seems to be possible using JS API… but I need to pass items list (available in PHP)

    What I’ll try :

    managing add/remove hook using JS API
    launch an ajax request that manage the selected list (as global) and add/remove items depending on the selection.

    I need to filter the available items through javascript by reading through ajax the PHP list …

    Should do the trick but it seems hi level dev…

  • Thank you, John and Christian.

    I just want to make the lifes of my content editors a little bit easier but, other than that, it is not an issue for me now. I can deal with possible double selections from the templates.

    The new JS API looks good! I’ll try to have a proper look when I find some time.

  • Partially done.

    All in Javascript.
    – able to dynamically get selections and put them in a global array.
    – able to filter the selection choices with acf JS filter.

    Need to put all these things together… and exclude already selected items.

    stay tuned

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.