Home Forums Bug Reports Conditional fields data stored when condition not met


Conditional fields data stored when condition not met

  • Hello,
    I have worked on several projects where I have set a field using conditional to detect whether another field is set. If the condition is no longer met the data is still stored which breaks the frontend.

    For example I’ve got a checkbox field called “Show Price”, and another field (“Price”) which shows conditionally if the checkbox is ticked. If the checkbox is unticked at a later date, the data for price is retained so still shows on the frontend.

    Would it be possible to implement something so that data previously conditionally met is removed if the condition no longer applies? Or even add an option in settings that allows admin to ensure this?

    Kind regards

  • There isn’t a setting to do this and this topic has come up in the past. When the field is hidden by conditional logic it is not submitted. Anything that is not submitted is not updated. This is a JS only thing and does not effect the fields. When fields are being saved ACF is unaware of the conditional logic associated with each field……

    Long story short: If you want to do this then you need to add your own filters/actions to accomplish it. acf/save_post

    When building templates you should not be basing display of the field on the content of the conditional field but on the condition field.

    Let’s say that I have 2 fields “show_price” and another field “price”

    if (get_field('show_price')) {
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Conditional fields data stored when condition not met’ is closed to new replies.