View on
Terrence Brannon > Javascript-Select-Chain > Javascript::Select::Chain::Nested



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.04   Source  


Javascript::Select::Chain::Nested - arbitrary depth DHTML select pulldowns



  use Javascript::Select::Chain::Nested;


This module does the same thing as Javascript::Select::Chain but it expects the data structure to look a little different. I do not recommend the use of this module because it is actually harder to generate the intricately nested structures that it requires as opposed to the flat and simple ones used by J::S::C.

I don't recommend that you use this module, but it is here as proof of concept of TMTOWTDI.


There is less redundancy in way of describing the chain of selects, but I actually found it harder to generate from database queries. Personally, I only use the "flat" data structure described in Javascript::Select::Chain.

selectchain( $model , $options )

selectchain() takes two arguments. $model is a hash reference with two keys, data and listgroupname. The value of the key listgroupname is exactly what is referred to in the original docs. See in the distribution for a sample usage. The value of the key data is an array reference in which each element completely represents one pulldown in the chain. Summarily, here is $model at the highest level:

   data          =>  [ $level1, $level2, $level3 ],
   listgroupname => $listgroupname                  # e.g., 'vehicles'

Now, we go into how each level looks. In words, each level is an array reference in which each element is a hash reference. Said hash reference has a key which is the first-list-name or second-list-name or whatever-list-name, depending on what level we are at. The value of said key is an array reference of $list_item, where $list_item is

   [  $option_text, $option_value => $next_list_name ]

Here is a sample level, completely described:

 my $level1 =
   { 'car-makers' =>
      [  "Select a maker", ""          => "dummy-list"  ],
      [  "Toyota",         "Toyota"    => "Toyota"     ],
      [  "Honda",          "Honda"     => "Honda"       ],
      [  "Chrysler",       "Chrysler"  => "Chrysler", 1  ],
      [  "Dodge",          "Dodge"     => "Dodge" ],
      [  "Ford",           "Ford"      => "Ford" ]
  ] ;

NOTE WELL: even if a list item only has one element they structure must still be maintained. For example, here is the start of a level 2 description. Note how much boilerplate was around the value to the key dummy-list even though it only had one element:

 my $level2 =

   { 'dummy-list' => 
      [ "Not available", "" => "dummy-sub"] 
     ] },

   { Toyota => 
      ["--- Toyota vehicles ---", "" => "dummy-list" ],
      [ "Cars",    "car",            => "Toyota-Cars"            ],
      [ "SUVs/Van", "suv",           => "Toyota-SUVs/Van"  ],
      [ "Trucks", "truck",           => "Toyota-Trucks", 1 ]
  ... in the distro contains a complete example to generate the 3-level hierarchy shown at


None by default. selectchain can be exported.




Terrence Brannon, <>


Copyright (C) 2004 by Terrence Brannon.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: