Re: inflating columns to objects
[prev]
[thread]
[next]
[Date index for 2004/10/27]
I wrote:
> I'm having a problem on a Maypole edit page, but I think the problem is
> something I'm doing wrong in Class::DBI with respect to Class::DBI::AsForm.
>
> I'm trying to use an object to represent a column:
>
> seq LONGTEXT NOT NULL,
> INDEX (seq(10))
>
> The value in the database is a potentially long string (and that is what
> I want to keep in the database :) but when it is displayed, I want to
> format it into lines of a reasonable length. I have written a class (see
> below) and added this line in my driver class (which isa Class::DBI):
>
> QD1::Sequence->has_a(seq => 'my_seq', deflate => 'deflate');
>
> This works when displaying a list, but when I click on edit I get an
> empty space where the textbox should be:
My debugging has thrown up a possibility :)
Class::DBI::AsForm::to_field is what is called on the template to
display the column. Within that routine it calls _to_textarea, which
looks like this:
sub _to_textarea {
my ($self, $col) = @_;
my $a = HTML::Element->new("textarea", name => $col);
if (ref $self) { $a->push_content($self->$col) }
$OLD_STYLE && return $a->as_HTML;
$a;
}
What's happening is that when it says { $a->push_content($self->$col) }
my inflated object is getting pushed into @a->_content. This seems to be
A Bad Thing and results in nothing being output by the element when the
HTML::Element::as_xml method is called on it. If I change that line to read:
if (ref $self) { $a->push_content('' . $self->$col) }
then the formatted content of my column gets displayed in a textarea
element as it should. But I have no idea whether my change fixes a bug
in AsForm or breaks some other cases, or whether there's a better fix.
Does this inspire anybody to see a good solution to my problem?
Thanks, Dave
|
(message missing)
|