Open apokyro opened 9 years ago
Hi @apokyro. I have fixed this issue, now all the conditionals are available from the beginning.
Regarding the conditional in the radio, can you give a use case so I can decide the best approach?
Hi again. I tested and it works perfect. Thanks
In my project I want to let the user select a layout in a radio form like the attach image:
So, depending the radio selection I want to display fields. Is that possible?
Thanks
Hi @apokyro. I have added support to radio input type. I also included an example in the example-functions.php file.
Thanks @jcchavezs. I appreciate your help. I will tested and if I found something I will post back. Thanks again.
How to use this as a part of theme not plugin ? I'm using a Select with id "select_style" with options
'options' => array( 'first_style' => 'First Style', 'second_style' => 'Second Style', 'third_style' => 'Third Style', )
and I want when I select First Style, a text field with id "add_title" displayed, when I select Second Style, the text field disappeared and colorpicker with id "article_bg" displayed and so on....
How can I do this step by step?
You can add to your theme folder the plugin like this:
theme_name/folder_name/cmb2-conditionals/
then include this line to your functions.php
require get_template_directory() . '/folder_name/cmb2-conditionals/cmb2-conditionals.php';
Last change this code from cmb2-conditionals.php
wp_enqueue_script('cmb2-conditionals', plugins_url('/cmb2-conditionals.js', __FILE__ ), array('jquery'), '1.0.2', true);
to this
wp_enqueue_script( 'cmb2-conditionals', get_template_directory_uri(). '/folder_name/cmb2-conditionals/cmb2-conditionals.js', array( 'jquery' ), '1.0.2', true);
I think this could work.
Hi apokyro, I did all that as you say , and in cmb-functions.php which exists in main cmb folder "not cmb2-conditionals function file".
I added this code but it didn't work on changing selections: the text field is always displayed.
function cmbcond(array $cmbcond){ $cmbcond[] = array( 'title'=> 'Conditional Select', 'id'=> 'condsecy', 'object_types'=> array('page','post'), 'fields'=> array(
array(
'name'=>'Select',
'id'=>'mycondselect',
'type'=> 'select',
'options'=>array(
'one'=>'One',
'two'=>'Two',
'three'=>'Three',
),
),
array( 'name'=> 'My Text', 'id'=> 'cmbcondtxt', 'type'=> 'text', 'attributes' => array(
'data-conditional-id' => 'mycondselect',
'data-conditional-value' => 'two',
)
),
)
);
return $cmbcond;
} add_filter('cmb2_meta_boxes','cmbcond');
What's wrong with my code?
Thanks.
Hi, great addon for CMB2!
I just give it a try and it works well when you save a post, but before the first save it seems like doesn't. If I save the post then it's all good.
Also, is it possible to use the conditional display as a radio button? I tried it and it works only on select.
Thank you.