Form::Factory::Feature::Control::Required - Makes sure a value is set on a control


Form-Factory documentation Contained in the Form-Factory distribution.

Index


Code Index:

NAME

Top

Form::Factory::Feature::Control::Required - Makes sure a value is set on a control

VERSION

Top

version 0.020

SYNOPSIS

Top

  has_control last_name => (
      control => 'text',
      features => {
          required => 1,
      },
  );

DESCRIPTION

Top

Reports a check error if the required value is not set. On scalar value controls, it checks that the value has a length greater than zero. On list value controls, it makes sure the list of selected items has more than zero elements.

METHODS

Top

check_control

No op.

check

Reports an error if a scalar value does not have a length greater than 0. Reports an error if a list value has 0 items in the list.

AUTHOR

Top

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Top


Form-Factory documentation Contained in the Form-Factory distribution.
package Form::Factory::Feature::Control::Required;
BEGIN {
  $Form::Factory::Feature::Control::Required::VERSION = '0.020';
}
use Moose;

with qw( 
    Form::Factory::Feature 
    Form::Factory::Feature::Role::Check
    Form::Factory::Feature::Role::Control
    Form::Factory::Feature::Role::CustomControlMessage
);

use Carp ();

sub check_control { }

sub check {
    my $self    = shift;
    my $control = $self->control;

    if ($control->has_current_value) {
        $self->result->is_valid(1);
    }

    else {
        $self->control_error('the %s is required');
        $self->result->is_valid(0);
    }
}

1;