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
Post a Comment