ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Chained select boxes

October 29, 2010 6:21pm

Subscribe [11]
  • #1 / Oct 29, 2010 6:21pm

    ingriddesign

    12 posts

    I don’t suppose anyone has worked up an EE2-friendly version of this little beauty? If anyone knows of anything, a heads up would be much appreciated! Thanks.

    http://5pieces.com/blog/chained-selects-for-expressionengine/

  • #2 / Oct 29, 2010 10:25pm

    benallen

    2 posts

    Oh wow that’s awesome. I’m subscribing to this thread hoping someone comes up with something…

  • #3 / Nov 02, 2010 12:21pm

    ingriddesign

    12 posts

    I’m having a friend look into it, I’ll keep you posted if he can come through on it.

    Oh wow that’s awesome. I’m subscribing to this thread hoping someone comes up with something…

  • #4 / Nov 02, 2010 7:24pm

    Sue Crocker

    26054 posts

    I don’t know if you realize this, but the author of this is a TSS here at EllisLab. 😊 He may or may not be willing to update the article. You’d have to ask.

  • #5 / Nov 03, 2010 11:15am

    ingriddesign

    12 posts

    To be honest, I figured that he was probably swamped with those kinds of script support requests so I just came straight to the forums 😊 If you don’t think it’d be annoying, I’ll definitely send a message over. Thanks!

  • #6 / Nov 03, 2010 5:51pm

    John Henry Donovan

    12339 posts

    Thanks for the interest. Here is what to update for it to work in EE2

    Original article :http://5pieces.com/blog/chained-selects-for-expressionengine/

    Ok so your header scripts remain the same. You can even use the latest jQuery.

    Category tags are updated to this

    
    
    

    And combobox template updated to this. Set to use PHP and parse on Input

    <?php
    $array = array();
    $cat_id =  $this->EE->input->get('_value');
    
        $query = $this->EE->db->query("SELECT title, url_title  FROM exp_category_posts INNER JOIN exp_channel_data USING(entry_id) INNER JOIN exp_channel_titles USING(entry_id) WHERE cat_id = '".$cat_id."' AND status ='open'"); 
             
                $array[] = array(null => 'Choose an article');
                foreach($query->result_array() as $row)
            {
                $entry_title = ($row['title']); 
                $entry_url_title = ($row['url_title']);
                $custom_url = '/news/'.$entry_url_title;
                $array[] = array($custom_url => $entry_title);
            
            }
    
    function php2js($a)
        {
            if (is_null($a)) return 'null';
            if ($a === false) return 'false';
            if ($a === true) return 'true';
            if (is_scalar($a)) {
                $a = addslashes($a);
                $a = str_replace("\n", '\n', $a);
                $a = str_replace("\r", '\r', $a);
                $a = preg_replace('{(</)(script)}i', "$1'+'$2", $a);
                return "'$a'";
            }
            $isList = true;
            for ($i=0, reset($a); $i<count($a); $i++, next($a))
                if (key($a) !== $i) { $isList = false; break; }
            $result = array();
            if ($isList) {
                foreach ($a as $v) $result[] = php2js($v);
                return '[ ' . join(', ', $result) . ' ]';
            } else {
                foreach ($a as $k=>$v)
                    $result[] = php2js($k) . ': ' . php2js($v);
                return '{ ' . join(', ', $result) . ' }';
            }
        }
    echo php2js( $array );
    
    
    ?>

    Any trouble let me know

  • #7 / Nov 04, 2010 12:24pm

    ingriddesign

    12 posts

    Thank you very much sir! You are truly a scholar and a gentleman! Now to figure out how to use it in conjunction with two levels of subcategories and I’m ready to launch. 😊 Seriously though, thanks for taking the time to revisit this, it’s much appreciated.

  • #8 / Dec 02, 2010 3:14pm

    ingriddesign

    12 posts

    We ended up still using your awesome code as a basis, but rewrote the comboboxes file as well as the JS initialization, which didn’t require JQuery (or the two plugin files) at all once finished. Once this project is done, I’ll post a link to the code as well as the site for an example.

    The version that is together now allows for pulling in all the top level categories in a category group. Then upon selecting one, placing it’s immediate subcategories into a second select box, the same for the third level, and then outputting entries into a 4th box.

    It’s a lot of boxes, but it’s a lot of information to filter through. Unfortunately the script does not take into account category structures that are only 2 levels deep or more than 3. It’s pretty specific, but easily worked around. Once I am allowed to post it, if anyone has security or speed considerations to bring up I’d love to hear them.

  • #9 / Dec 14, 2010 8:13am

    thkro

    2 posts

    I have setup the Pages module and would like the chained select to go to the “page_url” instead of the “url_title”. Played around with the PHP code by removing the “url_title” with “page_url” but that did not work.

    Any ideas?

  • #10 / Jan 17, 2011 11:33am

    ingriddesign

    12 posts

    I think you’d still want to use url_title. Do you have all the pages you want setup into categories? Are all the pages you want to use in the same channel?

    I have setup the Pages module and would like the chained select to go to the “page_url” instead of the “url_title”. Played around with the PHP code by removing the “url_title” with “page_url” but that did not work.

    Any ideas?

  • #11 / Mar 14, 2011 10:17pm

    mochajazz

    4 posts

    Hi everyone, i got this working to some degree in IE (with errors)
    but not at all in Chrome. (only tried those 2 browsers so far).

    I modified the query to pull categories and sub cat.s, the template and path references only though.
    cant see why it reports errors if the original code is ok.

    Just wondering Ingrid how you went with this. I would like to remove dependencies on google JS and
    the plugin js files and use only the ee bundled jquery libraries if possible.

    I would like to further develop this into a custom location fieldtype/plugin set of cascading select boxes,
    and any further info would be greatly appreciated. Im trying to avoid paying someone else to do it, but im very rusty and lazy 😊. i just cant figure out the JS/Jquery stuff!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases