Custom Fields
Support Meta Box Conditional Logic Disable (delete) fields that are hidden conditionally?

  • Creator
  • #11179
    Resolved calebcook

    I want to use conditional logic to actually remove/empty/disable a field, rather than just hide it from view. I notice that if you enter a value in the field and it is hidden later with CL, it still saves in the meta database.

    My current scenario for needing this (among others) is with address entries. 99% of the addresses are US-based, so I have a select box with the US States. However, if another country is selected, CL will hide the select box, and show a text field for text entry. The issue is that I have both fields saved, so if I were to select a state, then change the country, I can potentially have two fields for the State (or Province/Region)

    How can I disable or empty one field if it is hidden with CL?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
  • #11183

    Also - on the same topic, found a bug or unexpected behavior. I have the address fields bound to the Geolocate results - so they populate the country/city/etc. However, if a change is made in a box, Conditional Logic does not react to the changes unless another manual change is made.

    Scenario: CL will show/hide a select box of US States, based on whether US is selected as the country. However, if the country is changed by Geolocation binding, the CL does not trigger and make the change.

    Anh Tran


    Unfortunately, at the moment, CF only hides the fields. Clearing the values might lead to another unexpected behavior: users enter data in field A, and then hide it. After that, they changed their mind and show it. And they might expect the value they already entered.

    Let me work on the JS. I think I can add a custom JS event to the field when it's hid, so you can clear the value yourself. This is my idea:

    $( 'input' ).on( 'cl_hide', function() {
        this.value = '';
    } );

    Regarding the issue with Geolocation, I'll check and update. Thanks for letting me know.


    @calebcook I think this is based on something I got in the forum, but it looks through group field values being saved and removes empty values that are not visible upon submission.

    Anh Tran

    Hi again,

    We've just added the trigger cl_hide for inputs when they're hid. Now you can use the snippet I posted above. Please update.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.