Support

Account

Home Forums Backend Issues (wp-admin) Conditional Logic not clearing unused fields

Solved

Conditional Logic not clearing unused fields

  • I have two ACF Select fields, Grade and Standard.

    Grade and Standard

    Based on which Grade and which Standard is selected, a given Taxonomy Multi-Select is displayed using Conditional Logic.

    Conditional Logic

    There are about 21 Taxonomies that are presented via Conditional Logic depending on Grade and Standard.

    The problem occurs as follows:

    1) A user selects a Grade and Standard, selects items from the Taxonomy displayed via Conditional Logic, and then saves a draft or publishes the post.

    First Test

    2) The front end displays the correct Taxonomy items.

    First Display

    3) The user goes back and selects a different Grade or Standard, and selects different items from the newly displayed Taxonomy, then saves a draft or publishes the post.

    Second Test

    4) Both the OLD Taxonomy items and the NEW Taxonomy items both display on the front end.

    Second Display

    This seems counter-intuitive to me, as due to the Conditional Logic, the “old” Taxonomy field input should be cleared. I can write some PHP logic on the front end that checks the the Grade Level and Standard, and based on that, pulls only the correct Taxonomy item, but I’d like to avoid having to do so if possible. Currently it just sweeps the post_meta for every single taxonomy saved to that post, and displays whatever is saved.

    Thoughts?

  • Hi @pkarjala

    I see your issue. The thing about the conditional fields is that they are more about showing/hiding fields in the backend than deleting information.

    Consider a situation where someone want to show different information on a page depending on the season. For this they have radiobuttons to set which season it is and use conditional logic to show different fields (maybe wysiwyg, image field etc.) depending on autumn, winter, spring and summer. This information is the same each year. Then on the front-end they get the value of the radiobutton and show the fields accordingly. This way they can just switch between the different seasons and their information is still there ready to be used.

    What I’m trying to say is that it’s not entirely a black/white situation 🙂 I’ve had clients with similar situations as above which would hate it if a condition deleted the information. There’s also the danger of accidentally triggering a conditional (maybe accidentally check a different category on a post) and it would suck to have the content you just put in removed. But I guess you’d also have to save the post..

    This is just my thoughts on the subject.

    I’ll assign this to @elliot and we’ll see what he thinks 🙂

  • Totally understand the logic behind it, and agree that the current in-place implementation works as intended! I’ll work on coding a front-end fix that pulls depending on the Grade and Standard selected for the post, instead of just polling every single taxonomy in the post_meta.

    Thank you for the quick follow up.

  • No problem 🙂

    You could also probably do some custom javascript in the backend to deselect any previous values if a new grade and/or standard has been selected. It depends on where you want the extra code really.. 🙂

  • Yea, we’re likely going to add an action to “save_post” to clean up this post type on save.

    Thanks again for your assistance.

  • Hello,

    I’d like to know if there is any plan to avoid saving hidden fields ?

    In my case I’m putting a repeater in a flexible within a repeater etc. and the unused fields at each depth get stored into the DB for nothing.

    Thank you 🙂
    Vincent

  • I am looking for the same.

    Example: One Price number field, and if 2 other checkboxes (Free, As agreed) are marked Price number field is hidden and value is cleared.

    Difficult to make template code with if, else conditional if for instance both Price number field, and Free checkbox field are both with values.

    I guess I could solve it with Select field, 3 options and some conditional to show Number Price field if one option is chosen. But it is very strange setting for average Users (building classifieds site).

  • I just solved it somehow, different way. I did not know one field can be required and not required when hidden by conditional.

    – Showing all 3 fields
    – Number Price is required, just because I dont have fourth option.
    – When any of those 2 yes/no (new style button) are marked Numer Price field is hidden.
    – When one yes/no is checked hide other 2.

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

The topic ‘Conditional Logic not clearing unused fields’ is closed to new replies.