Subject: | _to_textfield won't fill value default parameter value if it is false (i.e. it won't display "0") |
Class-DBI-AsForm-2.3
Perl v5.8.4
Linux sib 2.4.20-pre7 #1 Tue Sep 24 12:12:24 PDT 2002 i686 GNU/Linux
I tracked this down because my 0 values kept disappearing from the database in a Maypole application. The stock Maypole 'edit' template calls to_field, which in turn calls _to_textfield. If the value of the item is 0, a value="0" statement does not get generated, so if you don't fill it back in again every time you edit a row...it just disappears.
*** /usr/local/share/perl/5.8.4/Class/DBI/AsForm.pm Tue Nov 9 16:51:16 2004
--- /home/sbessire/source/trunk/pc/experimental/Maypole/sib/sibas400/lib/Class/DBI/AsForm.pm Wed Nov 10 08:32:40 2004
***************
*** 107,115 ****
sub _to_textfield {
my ($self, $col) = @_;
! my $value = ref $self && $self->$col;
my $a = HTML::Element->new("input", type=> "text", name => $col);
! $a->attr("value" => $value) if $value;
$OLD_STYLE && return $a->as_HTML;
$a;
}
--- 107,115 ----
sub _to_textfield {
my ($self, $col) = @_;
! my $value = ref $self ? $self->$col : undef;
my $a = HTML::Element->new("input", type=> "text", name => $col);
! $a->attr("value" => $value) if length $value;
$OLD_STYLE && return $a->as_HTML;
$a;
}