The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

SYNOPSIS

# DISCOURAGED!

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

ABSTRACT

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

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

  • http://www.yxscripts.com/cs/chainedselects.html

  • http://www.dynamicdrive.com

  • http://www.quirksmode.org/

  • http://www.javascipts.com

TODO

  • must insure that lists have size to avoid err

  • test flat version

AUTHOR

Terrence Brannon, <tbone@cpan.org>

COPYRIGHT AND LICENSE

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.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 271:

You forgot a '=back' before '=head1'

Around line 281:

You forgot a '=back' before '=head1'