Subject: | Field labels are checked by string validity, not definedness |
Hi,
I am using HTML::FormHandler with Model::DBIC.
I'm on version 0.32002 of formhandler, and 0.12 of 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.
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?
yours,
Toby