Hi,
I am using HTML::FormHandler with the Model::DBIC.
I'm on version 0.32002 of formhandler, and 0.12 of HFH::Model::DBIC.
I have a DB class which has some fields with foreign keys on them, and
I'm using formhandler to give me auto-populated select boxes.
It worked quite well, except in one case.
Some of the foreign tables contain a set of values a bit like this:
0, <-- as in "", an empty string
1,A little bit
2,A bit more
3,A fair bit
4,Plenty
5,Many
The problem is that when formhandler renders the form, it doesn't
include the zero item in the select box.
There are also a bunch of warnings emitted, like:
Use of uninitialized value $string in substitution (s///) at
[..]/HTML/FormHandler/Field.pm line 346, 347, 348 and 349.
The code in question is:
sub default_render_filter {
my ( $self, $string ) = @_;
$string =~ s/&/&/g;
$string =~ s/</</g;
$string =~ s/>/>/g;
$string =~ s/"/"/g;
return $string;
}
Use of uninitialized value in concatenation (.) or string at
[..]/HTML/FormHandler/Render/Simple.pm line 195.
Which is in render_select().
However neither of those look like they're responsible for missing the
values out of the select boxes.
Looking at Model::DBIC, I see around line 350:
foreach my $row (@rows)
{
my $label = $row->$label_column;
next unless $label; # this means there's an invalid value
push @options, $row->id, $active_col && !$row->$active_col ? "[
$label ]" : "$label";
}
I have changed the middle line there to be:
next unless defined $label;
After this, the select boxes now include my zero-id and empty-label items.
Note the use of "defined" to check validity, rather than checking for
a truth value.
I think this is probably more correct to do this.
What do you think?
Thanks,
Toby