add extras to FormBuilder

This commit is contained in:
Doug Bell 2011-01-05 19:02:00 -06:00
parent d5d7d7ef0b
commit adcec8353a
2 changed files with 23 additions and 3 deletions

View file

@ -70,6 +70,14 @@ The name of the form. Not required, but recommended.
has 'name' => ( is => 'rw' );
=head2 extras
Any extra things to add to the <form> tag. Optional.
=cut
has 'extras' => ( is => 'rw', isa => 'Str', default => '' );
=head2 session
A WebGUI::Session object. Required.
@ -152,7 +160,7 @@ sub getHeader {
my @attrs = qw{ action method name enctype };
my $attrs = join " ", map { qq{$_="} . $self->$_ . qq{"} } grep { $self->$_ } @attrs;
my $html = sprintf '<form %s>', $attrs;
my $html = sprintf '<form %s %s>', $attrs, $self->extras;
return $html;
}

View file

@ -27,7 +27,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 69; # Increment this number for each test you create
plan tests => 77; # Increment this number for each test you create
#----------------------------------------------------------------------------
# Constructor and properties
@ -45,12 +45,14 @@ $fb = WebGUI::FormBuilder->new( $session,
enctype => 'application/x-www-form-urlencoded',
name => 'search',
method => 'get',
extras => q{onclick="alert('hi');"},
);
isa_ok( $fb, 'WebGUI::FormBuilder' );
is( $fb->method, 'get' );
is( $fb->action, '/myurl' );
is( $fb->enctype, 'application/x-www-form-urlencoded' );
is( $fb->name, 'search' );
is( $fb->extras, q{onclick="alert('hi');"} );
# Test mutators
is( $fb->method("POST"), "POST" );
@ -61,6 +63,17 @@ is( $fb->enctype('multipart/form-data'), 'multipart/form-data' );
is( $fb->enctype, 'multipart/form-data' );
is( $fb->name('myname'), 'myname' );
is( $fb->name, 'myname' );
is( $fb->extras(""), "" );
is( $fb->extras, "" );
# getHeader
like( $fb->getHeader, qr{ method="POST"} );
like( $fb->getHeader, qr{ action="/otherurl"} );
like( $fb->getHeader, qr{ enctype="multipart/form-data"} );
like( $fb->getHeader, qr{ name="myname"} );
$fb->extras(q{onclick="alert()"});
like( $fb->getHeader, qr{ onclick="alert\(\)"} );
#----------------------------------------------------------------------------
# Adding objects
@ -245,6 +258,5 @@ $fb->addField( 'submit', name => 'submit', label => 'Submit' );
#----------------------------------------------------------------------------
# toHtml
print $fb->toHtml;
#vim:ft=perl