From: Terrence Brannon Date: Mon, 9 Feb 2009 22:07:13 +0000 (-0500) Subject: unroll_select improvements X-Git-Tag: 5.200_001~40 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=3caedb5b3a025561935df4403083c02425cb3845;p=html-element-library.git unroll_select improvements --- diff --git a/lib/HTML/Element/Library.pm b/lib/HTML/Element/Library.pm index 60c7a4a..936840b 100644 --- a/lib/HTML/Element/Library.pm +++ b/lib/HTML/Element/Library.pm @@ -657,23 +657,30 @@ sub HTML::Element::unroll_select { my $select = {}; my $select_node = $s->look_down(id => $select{select_label}); + warn "Select Node: " . $select_node if $select{debug}; - my $option = $select_node->look_down('_tag' => 'option'); + unless ($select{append}) { + for my $option ($select_node->look_down('_tag' => 'option')) { + $option->delete; + } + } -# warn $option; + my $option = HTML::Element->new('option'); + warn "Option Node: " . $option if $select{debug}; $option->detach; while (my $row = $select{data_iter}->($select{data})) { -# warn Dumper($row); - my $o = $option->clone; - $o->attr('value', $select{option_value}->($row)); - $o->attr('SELECTED', 1) if ($select{option_selected}->($row)) ; - - $o->replace_content($select{option_content}->($row)); - $select_node->push_content($o); + warn "Data Row:" . Dumper($row) if $select{debug}; + my $o = $option->clone; + $o->attr('value', $select{option_value}->($row)); + $o->attr('SELECTED', 1) if (exists $select{option_selected} and $select{option_selected}->($row)) ; + + $o->replace_content($select{option_content}->($row)); + $select_node->push_content($o); + warn $o->as_HTML if $select{debug}; } @@ -769,13 +776,13 @@ This method is designed to take a hashref and populate a series of elements. For - - - + + +
1(877) 255-3239*********1(877) 255-3239*********
-In the table above, there are several attributes named C. If we have a hashref whose keys are the same: +In the table above, there are several attributes named C<< smap >>. If we have a hashref whose keys are the same: my %data = (people_id => 888, phone => '444-4444', password => 'dont-you-dare-render'); @@ -1229,6 +1236,8 @@ The C method has this API: option_selected => $closure, # boolean to decide if SELECTED data => $data # the data to be put into the SELECT data_iter => $closure # the thing that will get a row of data + debug => $boolean, + append => $boolean, # remove the sample