CMB2 Conditional
jQuery(document).ready( function ($) | |
{ | |
var module = $('.cmb-repeatable-grouping'); | |
var hidden = $(module).find('.cmb-repeat-group-field'); | |
var first = $(module).find('.cmb-repeat-group-field:first-of-type'); | |
var type = $(module).find('.cmb2_select'); | |
// $(hidden).hide(); | |
// $(first).show(); | |
$(type).on( 'change', function() { | |
var select_val = $(this).val(); | |
var iterator = $(this).parent().parent().parent().parent().attr('data-iterator'); | |
var field_prefix = '.cmb2-id-module-select-' + iterator +'-'; | |
switch(select_val) { | |
case 'image-module': | |
$( field_prefix + 'image-module-upload').show(); | |
$( field_prefix + 'image-module-text').show(); | |
$( field_prefix + 'post-module-main-cat').hide(); | |
$( field_prefix + 'post-module-sub-cat').hide(); | |
$( field_prefix + 'blank').hide(); | |
break; | |
case 'podcasts-module': | |
$( field_prefix + 'blank').show(); | |
$( field_prefix + 'post-module-main-cat').hide(); | |
$( field_prefix + 'post-module-sub-cat').hide(); | |
$( field_prefix + 'image-module-upload').hide(); | |
$( field_prefix + 'image-module-text').hide(); | |
break; | |
case 'posts-module': | |
$( field_prefix + 'post-module-main-cat').show(); | |
$( field_prefix + 'post-module-sub-cat').show(); | |
$( field_prefix + 'image-module-upload').hide(); | |
$( field_prefix + 'image-module-text').hide(); | |
$( field_prefix + 'blank').hide(); | |
break; | |
case 'newsletter-module': | |
$( field_prefix + 'blank').show(); | |
$( field_prefix + 'post-module-main-cat').hide(); | |
$( field_prefix + 'post-module-sub-cat').hide(); | |
$( field_prefix + 'image-module-upload').hide(); | |
$( field_prefix + 'image-module-text').hide(); | |
break; | |
case 'shop-module': | |
$( field_prefix + 'blank').show(); | |
$( field_prefix + 'post-module-main-cat').hide(); | |
$( field_prefix + 'post-module-sub-cat').hide(); | |
$( field_prefix + 'image-module-upload').hide(); | |
$( field_prefix + 'image-module-text').hide(); | |
break; | |
case 'tutorial-module': | |
$( field_prefix + 'blank').show(); | |
$( field_prefix + 'post-module-main-cat').hide(); | |
$( field_prefix + 'post-module-sub-cat').hide(); | |
$( field_prefix + 'image-module-upload').hide(); | |
$( field_prefix + 'image-module-text').hide(); | |
break; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment