Support Forum
Support › Meta Box Conditional Logic › Disable (delete) fields that are hidden conditionally?Resolved
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?
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.
Hello,
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.
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.
Anh, how do I get this working? Where do I add this code?
I have a member survey that has the first 6 fields set to hide questions. I need to delete the hidden field data when a logged in user saves the form.