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]
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>
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
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...
Yes, in your case, it needs to use term's name in the custom JS codes and in the shortcode [cred_show_group].