Skip Navigation

[Resolved] Set parent child taxonomy in accordian

This support ticket is created 6 years, 5 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 6 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#902639

How can I collapse/un-collapse a parent/child taxonomy?
My CRED form is overwhelming with every parent/child item displayed and I want to use a bootstrap accordion.

Also, is there a way to have the parent selected when a child of that parent is selected?

Thanks,
Anthony

#902774

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screen Shot 2018-05-24 at 11.24.11.png

Hi Anthony

I'm not sure I understand, if you could clarify.

When you say a parent/child taxonomy you mean a hierarchical taxonomy (like categories) that can have parent and child (and grandchild) terms, right?

In my screenshot you can see I have a status hierarchical taxonomy presented as a multi-select field.

What you are asking is to, what? Break a single input such as this up into accordions?

#902809
Screen Shot 2018-05-24 at 9.05.51 AM.png

Hi,

Yes a hierarchical taxonomy.
Attached is only a portion of the taxonomy. As you can see this is a long list. I'd like collapse the children so that the list is less daunting. Make sense?

Thanks,
Anthony

#903678

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Anthony

It is not possible to modify the markup output by the cred_field shortcode, so you'll need to use JavaScript and produce a bespoke solution that works with the generated markup.

I have worked out a possible solution for you below, but please bear in mind that providing custom code is outside of our support policy and if you need help expanding on the solution you would need to consult a developer.

You'll need to add a class "accordionize" to the form group for the taxonomy fields where you want this to work.

Here you can see I added it to my status taxonomy:

	<div class="form-group accordionize">
		<label>Statuses</label>
		[cred_field field='status'  display='checkboxes' output='bootstrap']
		[cred_field field='status_add_new' taxonomy='status' type='add_new']
	</div>

Now in the custom JS add the following code:

( function( $ ) {
	$( document ).ready( function(){

		// first hide the children
		$("[class*='tax-children-']").hide();

		// now add a change event handler to the parent inputs
		$(".accordionize ul.wpt-form-set-checkboxes > li.checkbox input").change( function(){

			// parent changed, toggle its children
			$(this).parent().parent().next("[class*='tax-children-']").toggle();

		});

	});
})( jQuery );

Because the toggle is handled by the state of the parent checkbox itself, then the parent will always be checked if a child term is checked.