Show/Hide Dependant Fields Implementation

Re: [gkornbluth] Show/Hide Dependant Fields Implementation

By Rusty - April 6, 2011 - edited: April 6, 2011

Yeah, I hear you there.

// For each section and list field, copy this block
// Fields will start hidden if they appear in any "fields to show" list
$GLOBALS['SHOWHIDE_DEPENDANT_FIELDS_CONFIG']['the_section_editor']['list_field_name'] = array(
// list option => fields to show
'' => array(), // show these fields when the topmost '<select>' option is selected
'List 1 - Opt 1' => array(),
'List 1 - Opt 2' => array(),
'List 1 - Opt 3' => array(),' => array('List 1', 'List 2'),
'_any_value_' => array('List 1'), // show these fields when a value not listed above is selected
);


Isn't altogether too intuitive. I understand the "my_section" and the "my_list_filed" however the array options is a bit confusing.

I want to make it so that if an option from a list is selected, that another, second list will be shown. But only if that option is selected, otherwise, it'd hide the second list.

Like this:

List 1 - Opt 1 (either 1 or 2 selected)
List 1 - Opt 2 (either 1 or 2 selected)
List 1 - Opt 3

=========== then IF....

List 1 - Opt 1
List 1 - Opt 2
List 1 - Opt 3 (3 selected)

With List 1 - Opt 3 selected then List 2 shows

List 2 - Opt 1
List 2 - Opt 2
List 2 - Opt 3
Rusty

Re: [Rusty] Show/Hide Dependant Fields Implementation

By Mikey - April 7, 2011

Have either of you figured out how to get this working? I can't seem to figure out what needs to be done so it will work.

Re: [zick] Show/Hide Dependant Fields Implementation

By robin - April 8, 2011

Hey,

Looks like we need to improve the documentation for this plugin! In the meantime I've put together a little example that should hopefully help.

This example is from a school, where they store both teachers and students in the same section named "person", but they want different fields to show based on "person_type".
person_type is a list field in the "person" section with the options- "teacher" and "student.

The show hide setup would look something like this:

$GLOBALS['SHOWHIDE_DEPENDANT_FIELDS_CONFIG']['person']['person_type'] = array(
// list option => fields to show
'' => array('name'), // show these fields when the topmost '<select>' option is selected
'teacher' => array('name', 'degree', 'parking_space_number'),
'student' => array('name', 'grade', 'parent_contact_number'),
);


Hope that helps,
Robin
Robin
Programmer
interactivetools.com

Re: [robin] Show/Hide Dependant Fields Implementation

By gkornbluth - April 9, 2011

Thanks Robin,

Makes more sense now.

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Show/Hide Dependant Fields Implementation

I've been getting this to work pretty well pulling tables its really cool but I see one limitation that I was curious if anyone could help with. Using single option pulldowns work however as soon as I try using multi select pulldowns or multi select checkboxes it breaks the show/hide and just displays them all. Is there perhaps something i'm missing?

Here is how I have it structured.

$GLOBALS['SHOWHIDE_DEPENDANT_FIELDS_CONFIG']['person']['person_type'] = array(
// list option => fields to show
'' => array('name'), // show these fields when the topmost '<select>' option is selected
'kids' => array('kids'),
'parents' => array('parents', 'date'),
);

I have tables in the DB for kids, parents and person

Re: [Hybrid] Show/Hide Dependant Fields Implementation

By robin - April 15, 2011

Hey Hybrid,

Multi selects are not supported yet, I'll let Chris know there is demand!

In the meantime, I'm thinking based on your example you could do something like this:
Add an option called "Kids and Parents" in your menu, then in the code...
$GLOBALS['SHOWHIDE_DEPENDANT_FIELDS_CONFIG']['person']['person_type'] = array(
// list option => fields to show
'' => array('name'), // show these fields when the topmost '<select>' option is selected
'kids' => array('kids'),
'parents' => array('parents', 'date'),
'_any_value_' => array('kids', 'parents', 'date'), // show these fields when a value not listed above is selected
);


Hope that helps,
Robin
Robin
Programmer
interactivetools.com

Re: [robin] Show/Hide Dependant Fields Implementation

By Perchpole - May 31, 2011

Hi, Robin -

I too have stumbled into an issue regarding this plugin and Multi-select menus.

Not being able to hide such fields renders the plugin fairly redundant for my particular project.

:0/

Perch

Re: [robin] Show/Hide Dependant Fields Implementation

By usadomains - August 15, 2011 - edited: August 15, 2011


Multi selects are not supported yet, I'll let Chris know there is demand! Ya, please get this updated to support this properly ... I can get it to work on the 1st list, but if I add additional ones for another field, they all show.