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

  • @christian-denatorange-fr

    Have you manage to get this working? Can you share you code if possible

    Much appreciated

    Cheers

  • 1st of all, sorry for the late reply.

    Yes sure I’ve done some code that allows to manage group of fields in order to add the possibility to make some value inclusion, exclusion.

    By adding a specific class to some fields, you can :
    – group fields
    – insert value from a group
    – exclude value from a group
    – Mix all this.

    It is a JS lib (but with some jQuery code, not 100% migrated to vanilla js ).

    It is running everyday without any problem (in my site context) without enhancements since more than one year.

    You can find it here : https://github.com/chdenat/acf-xtend

    Feel free to contact me for further explanation.

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

The topic ‘Hide values that have been selected in other field’ is closed to new replies.