Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use get_default_value in Submit/Reset fields

  • Loading branch information...
commit 64aa97ed1b0c4d74572f2037cde61d40d82033b9 1 parent 44918fe
@gshank authored
Showing with 34 additions and 1 deletion.
  1. +5 −1 lib/HTML/FormHandler/Field/NoValue.pm
  2. +29 −0 t/fields/novalue.t
View
6 lib/HTML/FormHandler/Field/NoValue.pm
@@ -7,7 +7,7 @@ extends 'HTML::FormHandler::Field';
=head1 SYNOPSIS
This is the base class for the Submit & Reset fields. It can be used for fields that
-are do not produce valid 'values'. It should not be used for fields that
+do not produce valid 'values'. It should not be used for fields that
produce a value or need validating.
=cut
@@ -21,6 +21,10 @@ has 'value' => (
sub _result_from_fields {
my ( $self, $result ) = @_;
+ my $value = $self->get_default_value;
+ if ( $value ) {
+ $self->value($value);
+ }
$self->_set_result($result);
$result->_set_field_def($self);
return $result;
View
29 t/fields/novalue.t
@@ -0,0 +1,29 @@
+use strict;
+use warnings;
+use Test::More;
+use HTML::FormHandler::Test;
+
+{
+ package MyApp::Form::Test;
+ use HTML::FormHandler::Moose;
+ extends 'HTML::FormHandler';
+
+ has_field 'foo';
+ has_field 'bar';
+ has_field 'sbmt' => ( type => 'Submit', value => 'Test', default_method => \&default_submit );
+ sub default_submit {
+ my $self = shift;
+ my $value = $self->value;
+ $value .= "_from_method";
+ }
+
+}
+
+my $form = MyApp::Form::Test->new;
+ok( $form );
+my $expected =
+'<div><input id="sbmt" name="sbmt" type="submit" value="Test_from_method" /></div>';
+my $rendered = $form->field('sbmt')->render;
+is_html( $rendered, $expected, 'submit button renders ok' );
+
+done_testing;

0 comments on commit 64aa97e

Please sign in to comment.
Something went wrong with that request. Please try again.