Cagao has asked for the wisdom of the Perl Monks concerning the following question:
Basically this never gets to my validate method.field industry => { required => 0, min_length => 1, max_length => 255, validation => sub { _validate_industry( @_ ) }, label => 'Industry', }; $form = MyApp::Form::Customer->new( params => { industry => [ $query->param('industry') ] } );
I'm sure I'm doing something wrong here, but unsure as to what that is. It's strikes me as odd that the validate methods don't get fired for an empty string. Not firing for undef I would expect.sub _validate_keywords { my ($self, $this, $params) = @_; if ( $params->{ keywords } eq '-' && $params->{ industry } eq '-' +) { $self->error($this, "You must enter some keywords or choose an + industry."); } return 1; } sub _validate_industry { my ($self, $this, $params) = @_; if ( $params->{ keywords } eq '-' && $params->{ industry } eq '-' +) { $self->error($this, "You must enter some keywords or choose an + industry."); } return 1; } $form = MyApp::Form::Customer->new( params => { industry => $query +->param('industry') || '-', keywords => $query->pa +ram('keywords') || '-',
|
|---|