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


Javascript-Select-Chain documentation  | view source Contained in the Javascript-Select-Chain distribution.

Index


NAME

Top

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

SYNOPSIS

Top

# DISCOURAGED!

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

ABSTRACT

Top

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.

DESCRIPTION

Top

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 Car2.pm 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 ]
     ]
   },
  ...

Car2.pm in the distro contains a complete example to generate the 3-level hierarchy shown at www.xyscripts.com.

EXPORT

None by default. selectchain can be exported.

SEE ALSO

Top

* http://www.yxscripts.com/cs/chainedselects.html
* http://www.dynamicdrive.com
* http://www.quirksmode.org/
* http://www.javascipts.com

TODO

Top

* must insure that lists have size to avoid err
* test flat version

AUTHOR

Top

Terrence Brannon, <tbone@cpan.org>

COPYRIGHT AND LICENSE

Top


Javascript-Select-Chain documentation  | view source Contained in the Javascript-Select-Chain distribution.