From adcec8353a922c45468690c66dbe93d3418cabf9 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Wed, 5 Jan 2011 19:02:00 -0600 Subject: [PATCH] add extras to FormBuilder --- lib/WebGUI/FormBuilder.pm | 10 +++++++++- t/FormBuilder.t | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/FormBuilder.pm b/lib/WebGUI/FormBuilder.pm index 36a3c3890..0b61835a2 100644 --- a/lib/WebGUI/FormBuilder.pm +++ b/lib/WebGUI/FormBuilder.pm @@ -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
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 '', $attrs; + my $html = sprintf '', $attrs, $self->extras; return $html; } diff --git a/t/FormBuilder.t b/t/FormBuilder.t index f952cff64..034b34729 100644 --- a/t/FormBuilder.t +++ b/t/FormBuilder.t @@ -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