Re: [dfv] field filters not executed for optional?
Status: Inactive
Brought to you by:
markjugg
|
From: Jiří P. <ji...@ge...> - 2010-12-14 22:09:07
|
On 14.12.2010 22:29, Mark Stosberg wrote:
>> what I want to achieve is to filter checkbox values so that they are
>> either 1 or 0, ie no undef values.
>>
>> So I put them into optional and set up field_filters for them with an
>> sub like this
>>
>> sub checkbox_filter {
>> return defined $_[0]&& lc $_[0] eq 'on' ? 1 : 0;
>> }
>>
>> But it looks like the filed filters are never executed.
> They should be working. Could you supply a Test::More test case that
> shows they are not? Test::FormValidator may be useful.
>
> You could also post a version of your profile for us to review.
I stripped my profile to the following test case. The optiona; value is
not even amongst 'valid' fields. Did I misunderstood the '
missing_optional_valid' option?
#!/usr/bin/perl
use strict;
use warnings;
use Test::FormValidator;
my $profile = {
optional => [ 'approved'],
filters => ['trim'],
field_filters => {
approved => sub {
defined $_[0] && lc $_[0] eq 'on' ? 1 : 0;
}
},
missing_optional_valid => 1,
};
use Test::More tests => 2;
my $tfv = Test::FormValidator->new;
$tfv->profile($profile);
# check that the profile detects missing distribution_date
$tfv->check();
$tfv->valid_ok(['approved'], 'Unchecked checkbox is valid');
my $results = $tfv->results;
is($results->valid('approved'), 0, 'Unchecked checkbox is 0');
|