if (not $rel_meta->{args}{no_select} and not $args->{no_select})
{
$args->{class} = $fclass;
- $args->{items} = $self->$field;
+ my @itms = $self->$field; # need list not iterator
+ $args->{items} = \@itms;
return $self->_to_select($field, $args);
}
return;
sub _to_select {
my ($self, $col, $args) = @_;
$args ||= {};
-# Do we have items already ? Go no further.
+ # Do we have items already ? Go no further.
if ($args->{items} and ref $args->{items}) {
my $a = $self->_select_guts($col, $args);
$OLD_STYLE && return $a->as_HTML;
return $a;
}
-# Else what are we making a select box out of ?
+ # Else what are we making a select box out of ?
# No Column parameter -- means making a select box of args->class or self
# Using all rows from class's table
if (not $col) {
# related objects pre selected if object
# "Has many" -- Issues:
- # 1) want to select one from list if self is an object
+ # 1) want to select one or many from list if self is an object
# Thats about all we can do really,
# 2) except for mapping which is TODO and would
# do something like add to and take away from list of permissions for
# Hasmany select one from list if ref self
if ($rel_meta->{name} =~ /has_many/i and ref $self) {
- $args->{items} = [ $self->$col ];
+ my @itms = $self->$col; # need list not iterator
+ $args->{items} = \@itms;
my $a = $self->_select_guts($col, $args);
$OLD_STYLE && return $a->as_HTML;
return $a;
sub _hash_selected {
my ($args) = shift;
my $selected = $args->{value} || $args->{selected};
- return $selected unless $selected and ref $selected ne 'HASH';
- #warn "Selected dump : " . Dumper($selected);
+ #warn "**** SELECTED is $selected ****";
my $type = ref $selected;
+ return $selected unless $selected and $type ne 'HASH';
+ #warn "Selected dump : " . Dumper($selected);
# Single Object
if ($type and $type ne 'ARRAY') {
- return {$selected->id => 1};
+ my $id = $selected->id;
+ $id =~ s/^0*//;
+ return {$id => 1};
}
# Single Scalar id
elsif (not $type) {
my ($self, $col, $args) = @_; #$nullable, $selected_id, $values) = @_;
#$args->{stringify} ||= 'stringify_selectbox';
+
$args->{selected} = _hash_selected($args) if defined $args->{selected};
+ warn "*** Dumpe of selected " . Dumper( $args->{selected} );
my $name = $args->{name} || $col;
my $a = HTML::Element->new('select', name => $name);
$a->attr( %{$args->{attr}} ) if $args->{attr};
my $stringify = $args->{stringify} || '';
my @res;
for (@$items) {
- my $opt = HTML::Element->new("option", value => $_->id);
- $opt->attr(selected => "selected") if $selected->{$_->id};
+ my $id = $_->id;
+ my $opt = HTML::Element->new("option", value => $id);
+ $id =~ s/^0*//; # leading zeros no good in hash key
+ $opt->attr(selected => "selected") if $selected->{$id};
my $content = $stringify ? $_->stringify : "$_";
$opt->push_content($content);
push @res, $opt;