wordpress - How to make conditional field on cmb2 plugin? -


i want make condition members info page.

$biometabox[] = array(         'id' => 'first-section',         'title' => 'member data',         'object_types' => array('dausfmembers'),         'fields' => array(             array(             'name' => 'gender',             'type' => 'radio',             'id' => $dausf.'gender',             'options' => array(                 'male' => 'male',                 'female' => 'female'             )         ),           array(             'name' => 'gender',             'type' => 'radio',             'id' => $dausf.'mstatus',             'options' => array(                 'married' => 'married',                 'single' => 'single'             )         ),  

i want make if female , married show fileds in admin panel.

                   array(                         'name' => 'husband name',                         'type' => 'text',                         'id' => $dausf.'hname',                     ), 

can me out ??

"conditional fields" seem not integrated within cmb2 core yet. however, there's plugin called cmb2 conditionals might achieve functionality want.

after installing , setting plugin, it'd achieved setting fields follows:

a special attention 'attributes' key, can play per plugin's instructions.

$biometabox[] = array(     'id' => 'first-section',     'title' => 'member data',     'object_types' => array('dausfmembers'),     'fields' => array(         array(          'name' => 'gender',          'type' => 'radio',          'id' => $dausf.'gender',          'options' => array(             'male' => 'male',             'female' => 'female',         ),          'attributes' => array(          'required'    => 'required',         )     ),           array(          'name' => 'gender',          'type' => 'radio',          'id' => $dausf.'mstatus',          'options' => array(             'married' => 'married',             'single' => 'single',          ),          'attributes' => array(          'required'    => 'required',         )     ),          array(          'name' => 'husband name',          'type' => 'text',          'id' => $dausf.'hname',          'required' => true,         ),          'attributes' => array(          'required' => true, // required if visible.          'data-conditional-id' => $prefix . 'gender',          'data-conditional-value' => 'female',     ),          'attributes' => array(          'required' => true, // required if visible.          'data-conditional-id' => $prefix . 'mstatus',          'data-conditional-value' => 'married',     ), ...  ) ); 

you'll want check plugin's example functions here: https://github.com/jcchavezs/cmb2-conditionals/blob/master/example-functions.php

i hope manage make work. luck.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -