Skip Menu |
 

This queue is for tickets about the Class-DBI-AsForm CPAN distribution.

Report information
The Basics
Id: 77176
Status: open
Priority: 0/
Queue: Class-DBI-AsForm

People
Owner: Nobody in particular
Requestors: alain [...] knaff.lu
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: When using the "how" parameter of to_field, the input element does not show current value
Date: Sun, 13 May 2012 12:57:05 +0200
To: bug-Class-DBI-AsForm [...] rt.cpan.org
From: Alain Knaff <alain [...] knaff.lu>
Download (untitled) / with headers
text/plain 970b
Hello, I'm trying to use the Class::DBI::AsForm module to generate form elements for editing objects stored in a postgres DB. The declaration is as follows: create table employee ( id serial primary key, lastname varchar(255), firstname varchar(255) ); ... and the Perl class is declared as follows: package Vacations::Employee; use base 'Vacations::DBI'; Vacations::Employee->table('employee'); Vacations::Employee->columns(All => qw/id lastname firstname/); 1; When I do $employee->to_field('lastname') I get a text area, but I'd prefer to get a text field. So I used $employee->to_field('lastname','textfield'). Now I do get a text field, but the current value ("Knaff") is not filled in. If I declare lastname as char(255) rather than varchar(255) in the database, I do get a text field, with current value filled in, but I'm concerned that this may make the table take up more physical space. Any solution for this? Thanks, Alain
Download (untitled) / with headers
text/plain 536b
On Sun May 13 06:57:18 2012, alain@knaff.lu wrote: Show quoted text
> So I used $employee->to_field('lastname','textfield'). Now I do get a > text field, but the current value ("Knaff") is not filled in.
Found it. In to_field, we have the following code: if ($how and $how =~ /^(text(area|field)|select)$/) { no strict 'refs'; my $meth = "_to_$how"; return $class->$meth($field); } replacing the return line with return $self->$meth($field) (instance instead of class) fixes the issue.
Attached is a patch. With test.
Subject: asForm.patch
Download asForm.patch
text/x-diff 1.9k
diff -ur Class-DBI-AsForm-2.42/lib/Class/DBI/AsForm.pm Class-DBI-AsForm-2.42-ak/lib/Class/DBI/AsForm.pm --- Class-DBI-AsForm-2.42/lib/Class/DBI/AsForm.pm 2005-09-07 00:24:26.000000000 +0200 +++ Class-DBI-AsForm-2.42-ak/lib/Class/DBI/AsForm.pm 2012-05-13 14:58:33.000000000 +0200 @@ -86,7 +86,7 @@ if ($how and $how =~ /^(text(area|field)|select)$/) { no strict 'refs'; my $meth = "_to_$how"; - return $class->$meth($field); + return $self->$meth($field); } my $hasa = $class->__hasa_rels->{$field}; return $self->_to_select($field, $hasa->[0]) diff -ur Class-DBI-AsForm-2.42/t/01.t Class-DBI-AsForm-2.42-ak/t/01.t --- Class-DBI-AsForm-2.42/t/01.t 2005-09-07 00:22:15.000000000 +0200 +++ Class-DBI-AsForm-2.42-ak/t/01.t 2012-05-13 14:57:50.000000000 +0200 @@ -1,7 +1,7 @@ package Foo; use Test::More; eval "require DBD::SQLite" or plan skip_all => "Couldn't load DBD::SQLite"; -plan tests => 4; +plan tests => 5; package DBI::Test; use base 'Class::DBI'; @@ -40,15 +40,20 @@ "Ordinary text field OK"); Foo->has_a(bar => Bar); -is(Foo->to_field("bar"), "<select name=\"bar\"><option value=1>Hi</option></select>\n", +is(Foo->to_field("bar"), "<select name=\"bar\"><option value=\"1\">Hi</option></select>\n", "Select OK"); my $x = bless({id => 1, bar => Bar->retrieve_all(), baz => "Hello there"}, "Foo"); -my %cgi = ( id => '<input name="id" type="text" value=1> +my %cgi = ( id => '<input name="id" type="text" value="1" /> ', - bar => '<select name="bar"><option selected value=1>Hi</option></select> + bar => '<select name="bar"><option selected value="1">Hi</option></select> ', - baz => '<input name="baz" type="text" value="Hello there"> + baz => '<input name="baz" type="text" value="Hello there" /> ' ); + +my %one = ( id => '<input name="id" type="text" value="1" /> +'); + is_deeply({$x->to_cgi}, \%cgi, "All correct as an object method"); +is_deeply({id => $x->to_field("id", "textfield")}, \%one, "Field with 'how' parameter correct");


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.