Skip Navigation

[Resolved] Clear checkbox selections based on conditional display in cred form

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#1287209

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?

#1287559

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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

#1288491

Thank you very much Waqar for your support! My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.