Tell us what you are trying to do?
(Post Form related)
I have a custom field with multiple checkbox options (e.g. Option 1, Option 2).
Whenever Option 1 is selected, conditional display will show Taxonomy 1 (multiple select checkboxes).
Whenever Option 2 is selected, conditional display will show Taxonomy 2 (multiple select checkboxes).
If user selects Option 1 and checks some boxes associated with Taxonomy 1 and later decides to deselect Option 1, Taxonomy 1 options become hidden but the checked values are still selected as input.
Any suggestions on how to clear Taxonomy 1 selections whenever Option 1 is unchecked? Any easy workaround?
Is there any documentation that you are following?
Is there a similar example that we can see?
https://toolset.com/forums/topic/clear-fields-input-based-on-conditional-display-in-cred-form/
What is the link to your site?
Hi Andrei,
Thank you for waiting, while I performed some tests.
To make sure that all the checkboxes for a hidden taxonomy are also unchecked when the connected custom field's checkbox is unchecked, you'll need to include some custom jQuery script, in your form's "JS editor" tab:
Example:
jQuery(document).ready(function() {
// detect change in the value of checkboxes type custom field
jQuery('.wpt-form-set-checkboxes-wpcf-cat-options input[type="checkbox"]').change(function() {
if(!(this.checked)) {
// when the option is unchecked, get the value of that option
var returnVal = jQuery(this).data('value');
// if option with value 1 is disabled
if (returnVal == 1) {
// uncheck options for cat taxonomy 1
$('.wpt-form-set-checkboxes-cat-advantage input[type="checkbox"]').prop('checked', false);
}
// if option with value 2 is disabled
if (returnVal == 2) {
// uncheck options for cat taxonomy 2
$('.wpt-form-set-checkboxes-cat-disadvantage input[type="checkbox"]').prop('checked', false);
}
}
});
});
Notes:
1. Please replace "cat-options" with the actual slug of your custom field and "cat-advantage" and "cat-disadvantage" with the actual slugs of your two taxonomies, respectively.
2. Also this script assumes that options for the checkboxes type custom field are stored as "1", "2" and so on.
( screenshot: hidden link )
I hope this helps and for more personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar
Thank you very much Waqar for your support! My issue is resolved now. Thank you!