Home › Toolset Professional Support › [Resolved] Hide Parent Taxonomy in Cred Form
Problem: I have a Form that includes a taxonomy input field using checkboxes. I would like to disable or remove the top-level items in this checkbox group.
Solution: Customize the following JavaScript code to work with your site's content:
jQuery(document).ready(function(){ jQuery('.wpt-form-set.wpt-form-set-checkboxes-vyrobce > li > label').remove(); )};
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
Tagged: Content-submission forms, CRED API, Toolset Forms
Related documentation:
This topic contains 6 replies, has 2 voices.
Last updated by JakubV7709 5 years, 5 months ago.
Assisted by: Christian Cox.
Hi,
i´m trying to follow this solved suport ticket for hiding parent taxanomy, but i´m not able to setup it because of hidden link in ticket, which propably show class for div - could you help me please?
https://toolset.com/forums/topic/cred-form-make-parent-taxonomy-non-selectable/
<div class="col-sm-3" id="boxy"><div class="form-group"> <div class="myzebra"> <label>Partner level:</label> [cred_field field='partner-level' force_type='taxonomy' output='bootstrap' display='checkbox' class='myzebra'] [cred_field field="partner-level_add_new" taxonomy="partner-level" type="add_new"] </div></div> </div>
jQuery(document).ready(function($){ $('div.myzebra-taxonomy-hierarchical-checkbox-container').children('div.myzebra-taxonomy-hierarchical-checkbox').children('label.myzebra-style-label').children('input.myzebra-checkbox').attr( 'disabled', 'disabled' ) });
Thank you very much!
Hi, the example site set up for this issue has been deleted so the links aren't helpful. If you would like a more up-to-date solution, you can use the PHP get_terms filter to whitelist or blacklist specific terms. Here is an example:
function tssupp_restrict_terms( $terms, $taxonomies, $args, $term_query ){ // 1. pages where form (or search View) is inserted $pages = array( 118, 137 ); // 2. which taxonomy (slug) $taxonomy = 'status'; // 3. add terms to blacklist *OR* whitelist, not both $blacklist = array(); $whitelist = array( 'archived', 'completed' ); if ( is_page( $pages ) && $taxonomies[0] == $taxonomy ) { if ( !empty( $blacklist ) ) { foreach( $terms as $key => $term ){ if ( in_array( $term->slug, $blacklist ) ) { unset($terms[$key]); } } } elseif ( !empty( $whitelist ) ) { foreach( $terms as $key => $term ){ if ( !in_array( $term->slug, $whitelist ) ) { unset($terms[$key]); } } } } return $terms; } add_filter( 'get_terms', 'tssupp_restrict_terms', 10, 4 );
Hi Christian, thank you for response... but i havent got skills to update php like this unfortunately :-(. Your code is propably great, but i will spend a few hours to solve it by this way. Is here any differnet way to use simply JS in CRED form for just hide or make non selectable parent for taxanomy? Im not looking for unique solution - but im not able to figure out how to set the code above. Thank you so much.
It might be possible with JavaScript. Can you provide a URL where I can see this on your site? I will take a look and see what we can do.
Sure - please use my login credential.
After that you can find my requested CRED form in the middle blue box called "Řešení".
Thank you.
Here is code for this CRED Form:
[wpv-conditional if="( empty($[types usermeta='logospolecnosti' output='raw' current_user='true']) )"] <label><strong>Vložte logo v sekci Upravit můj profil</strong><br> <em>Bez vložení loga společnosti není možné vkládat příspěvky</em></label> [/wpv-conditional] [wpv-conditional if="( '[types usermeta='logospolecnosti' output='raw' current_user='true']' ne '' )"] [credform] <div class="container-fluid"> <div class="row"> <div class="form-group col-sm-8"> <label>Název řešení:</label> [cred_field field='post_title' class='form-control' output='bootstrap'] </div> <div class="form-group col-sm-4" style="border: 1px solid white; border-radius: 8px; padding:10px;"> <label>Typ:</label> [cred_field field='rozdeleni-reseni' force_type='field' class='form-control' output='bootstrap'] </div> </div> <div class="row"> <div class="form-group col-sm-8"> <label>Napište krátky popis řešení:</label> [cred_field field='post_excerpt' force_type='field' class='form-control' output='bootstrap'] </div> <div class="form-group col-sm-4" style="border: 1px solid white; border-radius: 8px; padding:10px;"> <label>Vhodné pro oddělení:</label> [cred_field field='zamereni' force_type='taxonomy' output='bootstrap' display='checkbox'] </div> </div> <div class="row"> <div class="form-group col-sm-12"> <label>Popis řešení:</label> [cred_field field='post_content' force_type='field' class='form-control' output='bootstrap'] </div> </div> <div class="row"> <div class="form-group col-sm-3"> <label>Možnost implementace:</label> [cred_field field='implementace' force_type='field' class='form-control' output='bootstrap'] </div> <div class="form-group col-sm-3"> <label>Varianta:</label> [cred_field field='varianta' force_type='field' class='form-control' output='bootstrap'] </div> <div class="form-group col-sm-3"> <label>Podpora:</label> [cred_field field='podpora' force_type='field' class='form-control' output='bootstrap'] </div> <div class="form-group col-sm-3"> <label>Skype prezentace:</label> [cred_field field='prezentace-online' force_type='field' class='form-control' output='bootstrap'] </div> </div> <div class="row"> <div class="form-group col-sm-6"> <label>Vložte obrázek na titulní kartu:</label> [cred_field field='_featured_image' force_type='field' class='form-control' output='bootstrap'] </div> <div class="form-group col-sm-6"> <label>Vložte další fotky do galerie (printscreen, ukázky apod.):</label> [cred_field field='foto-reseni' force_type='field' class='form-control' output='bootstrap'] </div> </div> <div class="row"> <div class="form-group col-sm-4"> <label>Odkaz na video (youtube):</label> [cred_field field='odkaz-na-video' force_type='field' class='form-control' output='bootstrap'] </div> <div class="form-group col-sm-4"> <label>Produktový list v PDF:</label> [cred_field field='produktovy-list' force_type='field' class='form-control' output='bootstrap' preview='url'] </div> </div> <div class="row"> <div class="form-group col-sm-8"> <label>Vložte e-mail na produktového/obchodního manažera pro příjem poptávek:</label> [cred_field field='kontakt-na-produktoveho-manazera' force_type='field' class='form-control' output='bootstrap'] </div> </div> </div> <div class="row"> <div class="form-group col-sm-4"> <label>Vyberte kategorie zaměření řešení:</label> [cred_field field='firemni-reseni' force_type='taxonomy' output='bootstrap' display='checkbox'] </div> <div class="form-group col-sm-4"> <label>Vyberte vhodný obor pro řešení:</label> [cred_field field='obor' force_type='taxonomy' output='bootstrap' display='checkbox'] </div> <div class="form-group col-sm-4"> <label>Zvolte výrobce:</label> <div class="vyrobceform"> [cred_field field='vyrobce' force_type='taxonomy' output='bootstrap' display='checkbox' class='vyrobceform'] [cred_field field="vyrobce_add_new" taxonomy="vyrobce" type="add_new"]</div> </div> </div> <div class="row"> <div class="col-sm-6"> <div id="grecap"> [cred_field field='recaptcha' class='form-control' output='bootstrap'] </div> </div> <div class="row"> <div class="col-sm-12"> [cred_field field='form_messages' class='alert alert-warning'] </div> </div> <div class="row" style="display: none"> <div class="col-sm-12"> [cred_field field='placeny-clanek' force_type='field' class='form-control' output='bootstrap' value='2'] </div> </div> <div class="row"> <div class="col-sm-12"> <label>Všeobecné obchodní podmínky ICT Portálu k dispozici <a href="<em><u>hidden link</u></em>" target="_blank" rel="noopener noreferrer">zde</a></label> [cred_generic_field type='radio' field='souhlasVOP' class='souhlas'] { "required":0, "default":[], "options":[{"value":"0","label":"Ne, nejsem seznámen s VOP ICT Portálu"},{"value":"1","label":"Ano, potvrzuji seznámení s VOP ICT Portálu"}] } [/cred_generic_field] </div> </div> [cred_show_group if="( $(souhlasVOP) eq '1' )" mode="fade-slide"] <div class="row"> <div class="col-sm-12"> <center>[cred_field field='form_submit' output='bootstrap' value='Potvrdit zveřejnění' class='button']</center> </div> </div> [/cred_show_group] [/credform] [/wpv-conditional]
To disable the checkboxes:
jQuery(document).ready(function(){ jQuery('.wpt-form-set.wpt-form-set-checkboxes-vyrobce > li > label > input.checkbox').attr('disabled','disabled'); });
To remove the top level items:
jQuery(document).ready(function(){ jQuery('.wpt-form-set.wpt-form-set-checkboxes-vyrobce > li > label').remove(); )};
My issue is resolved now. Thank you!
I solved it by this:
jQuery(document).ready(function(){ jQuery('.wpt-form-set.wpt-form-set-checkboxes-vyrobce > li > label > input.checkbox').attr('disabled','disabled').remove(); });