HTML::Shakan::Field::Choice - choice field


HTML-Shakan documentation Contained in the HTML-Shakan distribution.

Index


Code Index:

NAME

Top

HTML::Shakan::Field::Choice - choice field

SYNOPSIS

Top

    use HTML::Shakan::Field::Choice;
    HTML::Shakan::Field::Choice->new(
        name => 'pref',
        choices => [qw/tokyo osaka kyoto/],
    );

    # or shortcut
    use HTML::Shakan::Fields;
    ChoiceField(
        name => 'pref',
        choices => [qw/tokyo osaka kyoto/],
    );

    # if you want radio button
    ChoiceField(
        name => 'pref',
        choices => [qw/tokyo osaka kyoto/],
        widget => 'radio',
    );

DESCRIPTION

Top

Choice field implementation. This field may show in html as <select></select> tag.

base class

Top

HTML::Shakan::Field

SEE ALSO

Top

HTML::Shakan


HTML-Shakan documentation Contained in the HTML-Shakan distribution.

package HTML::Shakan::Field::Choice;
use Any::Moose;
extends 'HTML::Shakan::Field';

has '+widget' => (
    default => 'select'
);

has choices => (
    is       => 'ro',
    isa      => 'ArrayRef',
    required => 1,
);

has 'id_tmpl' => (
    is      => 'ro',
    isa     => 'Str',
    default => 'id_%s_%s',
);

override 'get_constraints' => sub {
    my $self = shift;
    my ($name, $constraints) = super();

    return (
        $name => [
            @$constraints,
            ['CHOICE' => $self->choices]
        ]
    );
};

no Any::Moose;
__PACKAGE__->meta->make_immutable;
__END__