HTML::FormFu::Filter::CopyValue - copy the value from another field


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

Index


Code Index:

NAME

Top

HTML::FormFu::Filter::CopyValue - copy the value from another field

SYNOPSIS

Top

   elements:
      - type: Text
        name: username
      - type: Text
        name: nickname
        filters:
           - type: CopyValue
             field: username

DESCRIPTION

Top

Filter copying the value of another field if the original value of this field is empty.

CAVEATS

Top

If the original field contains an invalid value (a value that will be constrained through a constraint) that invalid value will be copied to this field (the field with the CopyValue filter). So, the user has to change two fields, or you can remove the invalid value in a custom constraint.

AUTHOR

Top

Mario Minati, mario.minati@googlemail.com

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::Filter::CopyValue;

use Moose;
extends 'HTML::FormFu::Filter';

has field => ( is => 'rw', traits => ['Chained'] );

sub filter {
    my ( $self, $value ) = @_;

    return $value
        if ( defined $value && length $value );

    my $field_name = $self->field
        or die "Parameter 'field' is not defined.";

    my $parent = $self->parent
        or die "Can't determine my parent.";

    my $field_value = $parent->form->input->{$field_name};

    return $field_value;
}

__PACKAGE__->meta->make_immutable;

1;

__END__