Grouping Sections
Hi all,
I am new with Redux so i don't know if anyone has a solution for this or if this is even possible. How can i group sections? I have a swtich field, and i want to a "section" only appear if the swtich is on. I have this:
array(
'id' => 'contact-info-enable',
'type' => 'switch',
'title' => 'Enable Contact Information?',
'default' => 0
),
Now if the switch is on, i need to appear below a section with some fields, do i have to put the 'required' in all fields? Would it not be better if we can group a list of fields, and only the parent field need the 'required' ? Something like:
array(
'id' => 'contact-info',
'type' => 'section',
'title' => 'Contact Information',
'required' => array('contact-info-enable', '=', '1'),
'subfields' => array(
array(
'id' => 'email-input',
'type' => 'text',
'title' => 'Email Account',
'desc' => 'Ex: [email protected]'
),
array(
'id' => 'phone-input',
'type' => 'text',
'title' => 'Phone Number',
'desc' => 'Ex: 123456789'
)
)
),
What do you think? Maybe this is already possible, but as i am new with Redux i don't see how can i do it. Can you give me some feedback?
Thanks a lot and continue the awesome work with Redux.
There is an example of this in the demo options code I found, so I can use the same method for my project. Check out the code below, it should answer your question.
array(
'id'=>'switch-custom',
'type' => 'switch',
'title' => __('Switch - Custom Titles', 'THEME_NAME'),
'subtitle'=> __('Look, it\'s on! Also hidden child elements!', 'THEME_NAME'),
"default" => 0,
'on' => 'Enabled',
'off' => 'Disabled',
),
array(
'id'=>'switch-fold',
'type' => 'switch',
'required' => array('switch-custom','=','1'),
'title' => __('Switch - With Hidden Items (NESTED!)', 'THEME_NAME'),
'subtitle'=> __('Also called a "fold" parent.', 'THEME_NAME'),
'desc' => __('Items set with a fold to this ID will hide unless this is set to the appropriate value.', 'THEME_NAME'),
'default' => 0,
),
Hi @killswitch20k thanks for your reply.
I already tried that before but its not what i need, that's only to hide/show a "related" field.
The section field has no subfields parameter. Nice idea though. If you want to code something like that up, I'm sure it could be added to the project. The seconds field it merely a marker to indicate that fields beneath it are indented, like a subfield, nothing more. Any field you want to hide with a switch needs to have the required parameter filled out, as shown in the sample @killswitch20k provided. There is no need to include a validate in your switch array.