HTML::FormFu::Element::DateTime - Date / Time combo field


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

Index


Code Index:

NAME

Top

HTML::FormFu::Element::DateTime - Date / Time combo field

SYNOPSIS

Top

    ---
    elements:
      - type: DateTime
        name: start_datetime
        label: 'Start:'
        auto_inflate: 1




DESCRIPTION

Top

Sub-class of Date element, providing extra hour and minute Select menus.

METHODS

Top

hour

Arguments: \%setting

Set values effecting the hour select menu. Known keys are:

name

Override the auto-generated name of the select menu.

default

Set the default value of the select menu

prefix

Arguments: $value

Arguments: \@values

A string or arrayref of strings to be inserted into the start of the select menu.

Each value is only used as the label for a select item - the value for each of these items is always the empty string ''.

minute

Arguments: \%setting

Set values effecting the minute select menu. Known keys are:

name

Override the auto-generated name of the select menu.

default

Set the default value of the select menu

prefix

Arguments: $value

Arguments: \@values

A string or arrayref of strings to be inserted into the start of the select menu.

Each value is only used as the label for a select item - the value for each of these items is always the empty string ''.

second

Arguments: \%setting

Set values effecting the second select menu. Known keys are:

name

Override the auto-generated name of the select menu.

default

Set the default value of the select menu

prefix

Arguments: $value

Arguments: \@values

A string or arrayref of strings to be inserted into the start of the select menu.

Each value is only used as the label for a select item - the value for each of these items is always the empty string ''.

field_order

Arguments: \@fields

Default Value: ['day', 'month', 'year', 'hour', 'minute']

Specify the order of the date fields in the rendered HTML.

If you want the second selector to display, you must set both /field_order and strftime yourself. Eg:

    elements:
      type: DateTime
      name: foo
      strftime: '%d-%m-%Y %H:%M:%S'
      field_order: ['day', 'month', 'year', 'hour', 'minute', 'second']

Not all fields are required. No single field can be used more than once.

CAVEATS

Top

See CAVEATS in HTML::FormFu::Element::Date

SEE ALSO

Top

Is a sub-class of, and inherits methods from HTML::FormFu::Element::Date HTML::FormFu::Element::_Field, HTML::FormFu::Element::Multi, HTML::FormFu::Element::Block, HTML::FormFu::Element

HTML::FormFu

AUTHOR

Top

Carl Franks, cfranks@cpan.org

LICENSE

Top

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


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

package HTML::FormFu::Element::DateTime;

use Moose;
extends 'HTML::FormFu::Element::Date';

use Moose::Util qw( apply_all_roles );
use Scalar::Util qw( blessed );

__PACKAGE__->mk_attrs(qw/ hour minute second /);

for my $name ( qw(
    printf_hour
    printf_minute
    printf_second
    ))
{
    has $name => (
        is      => 'rw',
        default => '%02d',
        lazy    => 1,
        traits  => ['Chained'],
    );
}

after BUILD => sub {
    my ( $self, $args ) = @_;

    $self->strftime( "%d-%m-%Y %H:%M" );

    $self->_known_fields( [qw/ day month year hour minute second /] );

    $self->field_order( [qw( day month year hour minute )] );

    $self->hour( {
            prefix => [],
        } );

    $self->minute( {
            prefix => [],
        } );

    $self->second( {
            prefix => [],
        } );

    $self->printf_hour  ('%02d');
    $self->printf_minute('%02d');
    $self->printf_second('%02d');
    
    return;
};

sub _add_hour {
    my ($self) = @_;

    my $hour = $self->hour;

    my $hour_name = $self->_build_name('hour');

    my @hour_prefix
        = ref $hour->{prefix}
        ? @{ $hour->{prefix} }
        : $hour->{prefix};

    @hour_prefix = map { [ '', $_ ] } @hour_prefix;

    my $element = $self->element( {
            type    => 'Select',
            name    => $hour_name,
            options => [
                @hour_prefix,
                map { [ $_, $_ ] } map { sprintf '%02d', $_ } 0 .. 23
            ],

            defined $hour->{default}
            ? ( default => sprintf '%02d', $hour->{default} )
            : (),
        } );

    apply_all_roles( $element, 'HTML::FormFu::Role::Element::MultiElement' );

    return;
}

sub _add_minute {
    my ($self) = @_;

    my $minute = $self->minute;

    my $minute_name = $self->_build_name('minute');

    my @minute_prefix
        = ref $minute->{prefix}
        ? @{ $minute->{prefix} }
        : $minute->{prefix};

    @minute_prefix = map { [ '', $_ ] } @minute_prefix;

    my @minutes = $self->_build_number_list( 0, 59, $minute->{interval} );

    my $element = $self->element( {
            type    => 'Select',
            name    => $minute_name,
            options => [
                @minute_prefix,
                map { [ $_, $_ ] } map { sprintf '%02d', $_ } @minutes
            ],

            defined $minute->{default}
            ? ( default => sprintf '%02d', $minute->{default} )
            : (),
        } );

    apply_all_roles( $element, 'HTML::FormFu::Role::Element::MultiElement' );

    return;
}

sub _add_second {
    my ($self) = @_;

    my $second = $self->second;

    my $second_name = $self->_build_name('second');

    my @second_prefix
        = ref $second->{prefix}
        ? @{ $second->{prefix} }
        : $second->{prefix};

    @second_prefix = map { [ '', $_ ] } @second_prefix;

    my @seconds = $self->_build_number_list( 0, 59, $second->{interval} );

    my $element = $self->element( {
            type    => 'Select',
            name    => $second_name,
            options => [
                @second_prefix,
                map { [ $_, $_ ] } map { sprintf '%02d', $_ } @seconds
            ],

            defined $second->{default}
            ? ( default => sprintf '%02d', $second->{default} )
            : (),
        } );

    apply_all_roles( $element, 'HTML::FormFu::Role::Element::MultiElement' );

    return;
}

__PACKAGE__->meta->make_immutable;

1;

__END__