Gapp
view release on metacpan or search on metacpan
lib/Gapp/Meta/Widget/Native/Trait/Form.pm view on Meta::CPAN
}
}
sub do_cancel_action {
my ( $self ) = @_;
return if ! $self->cancel_action;
my ( $action, @args ) = parse_action ( $self->cancel_action );
if ( is_CodeRef ($action) ) {
$action->( $self, \@args );
}
else {
$action->perform( $self, \@args );
}
}
sub do_ok_action {
my ( $self ) = @_;
return if ! $self->ok_action;
my ( $action, @args ) = parse_action ( $self->ok_action );
if ( is_CodeRef $action ) {
$action->( $self, \@args );
}
else {
$action->perform( $self, \@args );
}
}
sub find_fields {
my ( $self ) = ( @ _ );
my @fields;
for my $w ( $self->find_descendants ) {
push @fields, $w if is_FormField( $w );
}
return @fields;
}
sub _initialize_stash {
my ( $self ) = @_;
my $stash = $self->stash;
for my $w ( $self->find_fields ) {
$stash->store( $w->field, undef ) if ! $stash->contains( $w->field );
}
$stash->set_modified( 0 );
}
# update the values in the form
sub update {
my ( $self ) = ( @_ );
# update the stash if we have a context
$self->stash->update( $self->context ) if $self->context;
# update the widgets from the stash
$self->update_from_stash;
}
# update the values in the form (don't update the stash first)
sub update_from_stash {
my ( $self ) = @_;
# update the values in the form
for my $w ( $self->find_fields ) {
$w->set_is_updating( 1 );
$w->stash_to_widget( $self->stash ) if $w->field;
$w->set_is_updating( 0 );
}
}
sub update_stash {
my ( $self ) = shift;
warn '$form->update_stash deprecated, use $form->sync_stash';
$self->sync_stash( @_ );
}
sub sync_stash {
my ( $self ) = @_;
my $stash = $self->stash;
for my $w ( $self->find_fields ) {
$w->widget_to_stash( $stash ) if $w->field;
}
#$stash->set_modified( 1 );
}
package Gapp::Meta::Widget::Custom::Trait::Form;
{
$Gapp::Meta::Widget::Custom::Trait::Form::VERSION = '0.60';
}
sub register_implementation { 'Gapp::Meta::Widget::Native::Trait::Form' };
1;
__END__
=pod
=head1 NAME
Gapp::Meta::Widget::Native::Trait::Form - Form trait for widgets
=head1 DESCRIPTION
Apply this traits to widgets that you want to use as forms.
=head1 SYNOPSIS
use Gapp::Actions::Form qw( Ok );
Gapp::Window->new(
traits => [qw( Form )],
content => [
Gapp::HBox->new(
Gapp::Entry->new( field => 'user.name' ),
Gapp::Button->new( action => Ok ),
)
],
( run in 1.597 second using v1.01-cache-2.11-cpan-39bf76dae61 )