[html-formfu] Unable to create a Callback constraint via populate()

Michele Beltrame mb at cattlegrid.info
Wed Apr 30 13:49:04 BST 2008


Hello all!

I'm trying to use populate() to create a Callback constraint by passing
a code reference (HTML::FormFu::Constraint::Callback says passing a code
reference is possible). The error I get when passing a code ref is:

Can't store CODE items at /usr/lib/perl5/vendor_perl/5.10.0/HTML/FormFu/ObjectUtil.pm line 860.

Sample code which triggers the error follows:

---------------------------------------------------------------------------
use HTML::FormFu;

my $form = HTML::FormFu->new();

my $is_four = sub {
    my $value = shift;
    
    return ( $value == 4 ) ? 1 : 0;
};

$form->populate({
    id              => 'modify_form',
    enctype         => 'multipart/form-data',
    elements    => [{
        name    => 'birthday',
        type    => 'Text',
        label   => 'Birthday',
        constraints => [{
            type        => 'Required',
            message     => 'This field is required',
        }, {
            type        => 'Callback',
            callback    => $is_four,
        }],
    }],
});
--------------------------------------------------------------------------

Thanks a lot,
Michele.

-- 
Michele Beltrame
http://www.cattlegrid.info/
ICQ 76660101 - MSN mb at italpro.net



More information about the HTML-FormFu mailing list