X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FModel%2FCDBI%2FAsForm.pm;h=8a7f06c95e3f8237aad4d82009b0eba928353060;hb=ee812d68b34c0e43d89551e39ebf5b7d247ac5b6;hp=76003ff3cf811d4ea1e44c053a98ef12897ccee7;hpb=4f4bbd04570ff3c5f59f99c5cbf868d9b1a3da49;p=maypole.git diff --git a/lib/Maypole/Model/CDBI/AsForm.pm b/lib/Maypole/Model/CDBI/AsForm.pm index 76003ff..8a7f06c 100644 --- a/lib/Maypole/Model/CDBI/AsForm.pm +++ b/lib/Maypole/Model/CDBI/AsForm.pm @@ -1,6 +1,4 @@ package Maypole::Model::CDBI::AsForm; - -use Class::C3; use strict; use warnings; @@ -882,9 +880,9 @@ sub _to_bool_select { unless (defined $selected); my $a = HTML::Element->new("select", name => $col); - if ($args->{column_nullable} || $args->{value} eq '') { + if ($args->{column_nullable} || !defined $args->{value} ) { my $null = HTML::Element->new("option"); - $null->attr('selected', 'selected') if $args->{value} eq ''; + $null->attr('selected', 'selected') if (!defined $args->{value}); $a->push_content( $null ); } @@ -983,7 +981,8 @@ sub _to_foreign_inputs { my $rel_meta = $args->{related_meta} || $self->related_meta('r',$accssr); my $fields = $args->{columns}; if (!$rel_meta) { - $self->_croak( "No relationship for accessor $accssr"); + $self->_carp( "[_to_foreign_inputs] No relationship for accessor $accssr"); + return; } my $rel_type = $rel_meta->{name}; @@ -1173,11 +1172,13 @@ objects stringify method specified in $args->{stringify} as the content. Otherwi sub _options_from_objects { my ($self, $items, $args) = @_; my $selected = $args->{selected} || {}; - my $stringify = $args->{stringify}; my @res; for my $object (@$items) { - $stringify ||= $object->stringify_column; + my $stringify = $args->{stringify}; + if ($object->can('stringify_column') ) { + $stringify ||= $object->stringify_column if ($object->stringify_column && $object->can($object->stringify_column)); + } my $id = $object->id; my $opt = HTML::Element->new("option", value => $id); $id =~ s/^0*//; # leading zeros no good in hash key @@ -1194,7 +1195,8 @@ sub _options_from_arrays { my $selected = $args->{selected} || {}; my @res; my $class = $args->{class} || ''; - my $stringify = $args->{stringify} || $self->stringify_column; + my $stringify = $args->{stringify}; + $stringify ||= $self->stringify_column if ($self->can('stringify_column')); for my $item (@$items) { my @pks; # for future multiple key support push @pks, shift @$item foreach $class->columns('Primary'); @@ -1251,7 +1253,8 @@ sub _options_from_hashes { my $selected = $args->{selected} || {}; my $pk = eval {$args->{class}->primary_column} || 'id'; my $fclass = $args->{class} || ''; - my $stringify = $args->{stringify} || $self->stringify_column; + my $stringify = $args->{stringify}; + $stringify ||= $self->stringify_column if ( $self->can('stringify_column') ); my @res; for my $item (@$items) { my $val = defined $item->{$pk} ? $item->{$pk} : ''; @@ -1264,7 +1267,8 @@ sub _options_from_hashes { $content = $item->{$stringify}; } else { $content = join(' ', map {$item->{$_} } keys %$item); - } + } + $opt->push_content( $content ); push @res, $opt; }