Skip Navigation

[Resolved] Product Category Conditional Output for Group fields in Toolset Form (cred)

This support ticket is created 6 years, 4 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/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by Nashaat 6 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#915951

I am trying to show a group of field conditionally depending on which category is chosen by submitting a new product with Toolset Form.
I have 5 Categories "new car" used Car" etc...
the problem is when the user select a checkbox nothing happens.

<div class="form-group">
	<label>Product categories</label>
	[cred_field field='product_cat' display='checkbox' output='bootstrap']
</div>

[cred_show_group if="($(product_cat) eq  'usedcarcat' )"  mode='fade-slide']
Here are some post Fields
[/cred_show_group]
#915993

One more thing.
I am trying to add a default value of the product_cat when submitting new product.

but the value is not getting checked in the post form.

<div class="form-group">
	<label>Product categories</label>
	[cred_field field='product_cat' value='usedcarcat'  display='checkbox' output='bootstrap']
</div>
#916127

Hello,

Q1) the problem is when the user select a checkbox nothing happens.
Please make sure you are using the correct term's name in the shortcode [cred_show_group] attribute "if", it is not the term's slug.

Q2) but the value is not getting checked in the post form.
The value attribute works for the custom field, it does not work for taxonomy checkboxes field, in your case, you might consider using custom JS codes, for example, edit your Toolset form, in section "Content", click "JS Editor", add below codes:

jQuery(document).ready(function() {
    jQuery("input[data-value='usedcarcat']").prop("checked", true);
});

Same as Q1) Please replace "usedcarcat" with the term's name

#916197

Thanks Luo! Your Javascript code has solved the problem. but i had to change the usedcarcat to Used Cars. when i add the slug, the checkbox wont be checked, but when i add the name of the category then it works fine. like this:

jQuery(document).ready(function() {
    jQuery("input[data-value='Used Cars']").prop("checked", true);
});

about the first question also the same. slug value doesn't work with cred if conditions. so i had to change it to following:

This works.

<div class="form-group">
    <label>Product categories</label>
    [cred_field field='product_cat' display='checkbox' output='bootstrap']
</div>
 
[cred_show_group if="($(product_cat) eq  'Used Cars' )"  mode='fade-slide']
Here are some post Fields
[/cred_show_group]

so as i understand now product categories name is the value of the category? because slug name doesn't change anything with conditionals etc...

#916435

Yes, in your case, it needs to use term's name in the custom JS codes and in the shortcode [cred_show_group].

#917066

Thanks Luo!