From ab6e7c67ef9abea669105b1517a69973ef1f5919 Mon Sep 17 00:00:00 2001 From: Len Kranendonk Date: Fri, 29 Oct 2004 09:35:24 +0000 Subject: [PATCH] Added button --- docs/changelog/6.x.x.txt | 3 +- lib/WebGUI/Form.pm | 29 +++++++++++++++++- lib/WebGUI/HTMLForm.pm | 63 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 92 insertions(+), 3 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index e4b6cc6f4..6eba6f468 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -10,7 +10,8 @@ - Lots of GUID changes in Perl and SQL code, including: bugfix [1053187] - Bugfix [ 1055396 ] Template switching issue (Len Kranendonk) - + - WebGUI Operations are now dynamically loaded (Len Kranendonk) + - Added button to Form.pm / HTMLForm.pm (Len Kranendonk) 6.2.7 - Expanded upon the help for URL extensions. diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm index a5e896910..0ef777d8c 100644 --- a/lib/WebGUI/Form.pm +++ b/lib/WebGUI/Form.pm @@ -38,6 +38,7 @@ Base forms package. Eliminates some of the normal code work that goes along with use WebGUI::Form; + $html = WebGUI::Form::button({value=>"Click me!", extras=>qq|onclick="alert('Aaaaggggghhh!!!')"|}); $html = WebGUI::Form::checkbox({name=>"whichOne", value=>"red"}); $html = WebGUI::Form::checkList({name=>"dayOfWeek", options=>\%days}); $html = WebGUI::Form::combo({name=>"fruit",options=>\%fruit}); @@ -109,6 +110,31 @@ sub _fixTags { } +#------------------------------------------------------------------- + +=head2 button ( hashRef ) + +Returns a button. Use it in combination with scripting code to make the button perform an action. + +=head3 value + +The button text for this submit button. Defaults to "save". + +=head3 extras + +If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows: + + 'onClick="alert(\'You've just pushed me !\')"' + +=cut + +sub button { + my ($label, $extras, $subtext, $class, $output, $name, $value); + $value = $_[0]->{value} || WebGUI::International::get(62); + $value = _fixQuotes($value); + return '{extras}.'>'; +} + #------------------------------------------------------------------- =head2 checkbox ( hashRef ) @@ -1327,7 +1353,8 @@ sub submit { $value = $_[0]->{value} || WebGUI::International::get(62); $value = _fixQuotes($value); $wait = WebGUI::International::get(452); - return '{extras}.'>'; + return '{extras}.'>'; + } #------------------------------------------------------------------- diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm index 2daac7a1d..fccf27e19 100644 --- a/lib/WebGUI/HTMLForm.pm +++ b/lib/WebGUI/HTMLForm.pm @@ -38,6 +38,10 @@ Package that makes HTML forms typed data and significantly reduces the code need use WebGUI::HTMLForm; $f = WebGUI::HTMLForm->new; + $f->button( + -value=>"Click me!", + -extras=>qq|onClick="alert('Aaaaaaaggggghh!!!!')"| + ); $f->checkbox( -name=>"whichOne", -label=>"Is red your favorite?", @@ -176,6 +180,8 @@ $f->dynamicField(text, -label=>"Office Zip Code" ); + $f->trClass("class"); # Sets a Table Row class + $f->print; $f->printRowsOnly; @@ -197,7 +203,9 @@ sub _subtext { #------------------------------------------------------------------- sub _tableFormRow { unless ($_[0]->{_noTable}) { - return ''.$_[1].''.$_[2]."\n"; + my $class = $_[0]->{_class}; + $class = qq| class="$class" | if($class); + return ''.$_[1].''.$_[2]."\n"; } else { return $_[2]; } @@ -214,6 +222,45 @@ sub _uiLevelChecksOut { #------------------------------------------------------------------- +=head2 button ( value [ label, extras, subtext ] ) + +Adds a button row to this form. Use it in combination with scripting code to make the button perform an action. + +=head3 value + +The button text for this button. Defaults to "save". + +=head3 label + +The left column label for this form row. + +=head3 extras + +If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows: + + 'onClick="alert(\'Hello there!\')"' + +=head3 subtext + +Extra text to describe this form element or to provide special instructions. + +=cut + +sub button { + my ($output); + my ($self, @p) = @_; + my ($value, $label, $extras, $subtext) = rearrange([qw(value label extras subtext)], @p); + $output = WebGUI::Form::button({ + "value"=>$value, + "extras"=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + $self->{_data} .= $output; +} + +#------------------------------------------------------------------- + =head2 checkbox ( name [ label, checked, subtext, value, extras, uiLevel ] ) Adds a checkbox row to this form. @@ -2121,6 +2168,20 @@ sub timeField { } +#------------------------------------------------------------------- + +=head2 trClass ( ) + +Sets a CSS class for the Table Row. By default the class is undefined. + +=cut + +sub trClass { + my $self = shift; + my $class = shift; + $self->{_class} = $class; +} + #------------------------------------------------------------------- =head2 url ( name [ label, value, maxlength, extras, subtext, size, uiLevel ] )