How to setup dependent list

4 posts by 2 authors in: Forums > CMS Builder
Last Post: July 1, 2015   (RSS)

By Dave - June 30, 2015

Hi jsantari, 

It depends if you're doing on the frontend or in the CMSB.  

I think what you're looking for are called "chained Selects".   You can create all the related tables in CMSB but CMSB doesn't have a code generator for chained selects.  You'll need to create them by hand with some custom code (php, mysql, ajax, jquery, etc).  Here's some links to get you started: https://www.google.com/search?q=chained+selects

I've also seen components on the web where you output all the data into the source of the page (assuming you don't have thousands of records) and a premade javascript component builds chains selects from that.  So that can be an easier method if you can find a component that does close to what you need.

That's all for the frontend, if you're doing it in CMSB there's some basic support.  In the field editor create a list field and set the "List Options" to "Get Options from MySQL query", and then you'll see some additional options appear (Advanced Filter: Refresh list when this field changes).  It easier, but still takes a bit of custom MySQL unfortunately, though.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

By jsantari - July 1, 2015

Hi Dave,

Thanks for the response. I'm not worried about the front end, I can code that. Custom mysql is no problem. I guess what I need to know is how I access the trigger select value to pass to the custom mysql.

Example; if I had a states drop down and want the selected state to drive the options for the cities select.

Jim

By Dave - July 1, 2015

Hi jsantari, 

Say you had a list field called "cities".  

  • In the field editor, for cities: set List Options to: Get options from MySQL Query
  • Enter a query something like this: SELECT num, cityName FROM `<?php echo $TABLE_PREFIX ?>city` WHERE state = '<?php echo $ESCAPED_FILTER_VALUE ?>'
  • Set "Advanced Filter: Refresh list when this field changes: " to "State"

Then when state gets updated some ajax will be fired for the city pulldown to update its contents by rerunning the mysql query with the new escaped filter value (which would be the newly selected state).

Note that when you select these options in the field editor there is some inline documentation on the page to help you.

Let me know how it goes!

Dave Edis - Senior Developer
interactivetools.com