From c15cfa954f826df924be056c50ab1e5da4b03675 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 26 Jul 2005 21:54:47 +0000 Subject: [PATCH] added the hidden list field type --- lib/WebGUI/Form.pm | 42 -------- lib/WebGUI/Form/checkList.pm | 17 ++++ lib/WebGUI/Form/hiddenList.pm | 140 +++++++++++++++++++++++++ lib/WebGUI/Form/selectList.pm | 17 ++++ lib/WebGUI/HTMLForm.pm | 164 ++---------------------------- lib/WebGUI/i18n/English/WebGUI.pm | 6 ++ 6 files changed, 190 insertions(+), 196 deletions(-) create mode 100644 lib/WebGUI/Form/hiddenList.pm diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm index 0aa87feb1..d47db2d09 100644 --- a/lib/WebGUI/Form.pm +++ b/lib/WebGUI/Form.pm @@ -531,48 +531,6 @@ sub group { } -#------------------------------------------------------------------- - -=head2 hiddenList ( hashRef ) - -Returns a list of hidden fields. This is primarily to be used by the HTMLForm package, but we decided to make it a public method in case anybody else had a use for it. - -=head3 name - -The name of this field. - -=head3 options - -A hash reference where the key is the "name" of the hidden field. - -=head3 value - -An array reference where each value in the array should be a name from the hash (if you want it to show up in the hidden list). - -=head3 defaultValue - -This will be used if no value is specified. Should be passed as an array reference. - -=cut - -sub hiddenList { - my $params = shift; - my ($output, $key, $item); - my $values = $params->{value} || $params->{defaultValue}; - foreach $key (keys %{$params->{options}}) { - foreach $item (@{$values}) { - if ($item eq $key) { - $output .= hidden({ - name=>$params->{name}, - value=>$key - }); - } - } - } - return $output."\n"; -} - - #------------------------------------------------------------------- diff --git a/lib/WebGUI/Form/checkList.pm b/lib/WebGUI/Form/checkList.pm index c9f48afa0..86aa72779 100644 --- a/lib/WebGUI/Form/checkList.pm +++ b/lib/WebGUI/Form/checkList.pm @@ -17,6 +17,7 @@ package WebGUI::Form::checkList; use strict; use base 'WebGUI::Form::Control'; use WebGUI::Form::checkbox; +use WebGUI::Form::hiddenList; use WebGUI::International; use WebGUI::Session; @@ -141,7 +142,23 @@ sub toHtml { return $output; } +#------------------------------------------------------------------- +=head2 toHtmlAsHidden ( ) + +Creates a series of hidden fields representing the data in the list. + +=cut + +sub toHtmlAsHidden { + my $self = shift; + return WebGUI::Form::hiddenList->new( + value=>$self->{value}, + defaultValue=>$self->{defaultValue}, + name=>$self->{name}, + options=>$self->{options} + )->toHtmlAsHidden; +} 1; diff --git a/lib/WebGUI/Form/hiddenList.pm b/lib/WebGUI/Form/hiddenList.pm new file mode 100644 index 000000000..59146c5e6 --- /dev/null +++ b/lib/WebGUI/Form/hiddenList.pm @@ -0,0 +1,140 @@ +package WebGUI::Form::hiddenList; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2005 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use base 'WebGUI::Form::Control'; +use WebGUI::International; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::hiddenList + +=head1 DESCRIPTION + +Creates a list of hidden fields. This is to be used by list type controls (selectList, checkList, etc) to store their vaiuses as hidden values. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::Control. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + +#------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 options + +A hash reference containing name value pairs. The name of each pair will be used to fill the value attribute of the hidden field. Defaults to an empty hash reference. + +=head4 defaultValue + +value and defaultValue are array referneces containing the names from the options list that should be stored. + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + options=>{ + defaultValue=>{} + }, + defaultValue=>{ + defaultValue=>[] + } + }); + return $class->SUPER::definition($definition); +} + + +#------------------------------------------------------------------- + +=head2 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("hidden list","WebGUI"); +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +A synonym for toHtmlAsHidden. + +=cut + +sub toHtml { + my $self = shift; + $self->toHtmlAsHidden; +} + +#------------------------------------------------------------------- + +=head2 toHtmlAsHidden ( ) + +Renders an input tag of type hidden. + +=cut + +sub toHtmlAsHidden { + my $self = shift; + my $output; + foreach my $key (keys %{$self->{options}}) { + foreach my $item (@{$self->{values}}) { + if ($item eq $key) { + $output .= hidden({ + name=>$self->{name}, + value=>$self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($key))) + }); + } + } + } + return $output; +} + +#------------------------------------------------------------------- + +=head2 toHtmlWithWrapper ( ) + +A synonym for toHtmlAsHidden. + +=cut + +sub toHtmlWithWrapper { + my $self = shift; + return $self->toHtmlAsHidden; +} + + +1; + diff --git a/lib/WebGUI/Form/selectList.pm b/lib/WebGUI/Form/selectList.pm index 9680c0277..01c96a50b 100644 --- a/lib/WebGUI/Form/selectList.pm +++ b/lib/WebGUI/Form/selectList.pm @@ -16,6 +16,7 @@ package WebGUI::Form::selectList; use strict; use base 'WebGUI::Form::Control'; +use WebGUI::Form::hiddenList; use WebGUI::International; use WebGUI::Session; @@ -154,7 +155,23 @@ sub toHtml { return $output; } +#------------------------------------------------------------------- +=head2 toHtmlAsHidden ( ) + +Creates a series of hidden fields representing the data in the list. + +=cut + +sub toHtmlAsHidden { + my $self = shift; + return WebGUI::Form::hiddenList->new( + value=>$self->{value}, + defaultValue=>$self->{defaultValue}, + name=>$self->{name}, + options=>$self->{options} + )->toHtmlAsHidden; +} 1; diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm index dae0199b2..4ef001ca6 100644 --- a/lib/WebGUI/HTMLForm.pm +++ b/lib/WebGUI/HTMLForm.pm @@ -38,164 +38,20 @@ Package that makes HTML forms typed data and significantly reduces the code need use WebGUI::HTMLForm; $f = WebGUI::HTMLForm->new; - $f-asset( - -value=>$assetId, - -label=>"Pick an Asset" - ); - $f->button( - -value=>"Click me!", - -extras=>qq|onClick="alert('Aaaaaaaggggghh!!!!')"| - ); - $f->checkbox( - -name=>"whichOne", - -label=>"Is red your favorite?", - -value=>"red" - ); - $f->checkList( - -name=>"dayOfWeek", - -options=>\%days, - -label=>"Which day?" - ); - $f->codearea( - -name=>"stylesheet", - -label=>"Stylesheet" - ); - $f->color( - -name=>"highlightColor", - -label=>"Highlight Color" - ); - $f->combo( - -name=>"fruit", - -options=>\%fruit, - -label=>"Choose a fruit or enter your own." - ); - $f->contentType( - -name=>"contentType" - ); - $f->date( - -name=>"endDate", - -label=>"End Date", - -value=>$endDate - ); - $f->dateTime( - -name=>"endDate", - -label=>"End Date", - -value=>$endDate - ); -$f->dynamicField(text, - -name=>"firstName", - -label=>"First Name" - ); - $f->email( - -name=>"emailAddress", - -label=>"Email Address" - ); - $f->fieldType( - -name=>"dataType", - -label=>"Type of Field" - ); - $f->file( - -name=>"image", - -label=>"Image to Upload" - ); - $f->filterContent( - -name=>"filterThisContent", - -label=>"Filter This Content" - ); - $f->float( - -name=>"distance", - -label=>"5.1" - ); - $f->group( - -name=>"groupToPost", - -label=>"Who can post?" - ); - $f->hidden( - -name=>"wid", - -value=>"55" - ); - $f->HTMLArea( - -name=>"description", - -label=>"Description" - ); - $f->integer( - -name=>"size", - -label=>"Size" - ); - $f->interval( - -name=>"timeToLive", - -label=>"How long should this last?", - -intervalValue=>12, - -unitsValue=>"hours" - ); - $f->ldapLink( - -name=>"ldapLink", - -label="LDAP Connection" - ) - $f->password( - -name=>"identifier", - -label=>"Password" - ); - $f->phone( - -name=>"cellPhone", - -label=>"Cell Phone" - ); - $f->radio( - -name=>"whichOne", - -label=>"Is red your favorite?", - -value=>"red" - ); - $f->radioList( - -name=>"dayOfWeek", - -options=>\%days, - -label=>"Which day?" - ); - $f->raw( - -value=>"text" - ); - $f->readOnly( - -value=>"34", - -label=>"Page ID" - ); - $f->selectList( - -name=>"dayOfWeek", - -options=>\%days, - -label=>"Which day?" - ); - $f->submit; - $f->template( - -name=>"templateId", - -label=>"Page Template" + $f->someFormControlType( + name=>"someName", + value=>"someValue" ); + + Example: + $f->text( - -name=>"firstName", - -label=>"First Name" - ); - $f->textarea( - -name=>"emailMessage", - -label=>"Email Message" - ); - $f->timeField( - -name=>"endDate", - -label=>"End Date", - -value=>$endDate - ); - $f->url( - -name=>"homepage", - -label=>"Home Page" - ); - $f->whatNext( - -options=>\%options - ); - $f->yesNo( - -name=>"happy", - -label=>"Are you happy?" - ); - $f->zipcode( - -name=>"workZip", - -label=>"Office Zip Code" + name=>"title", + value=>"My Big Article" ); +See the list of form control types for details on what's available. + $f->trClass("class"); # Sets a Table Row class $f->print; diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm index 14ccc6810..9c4c120f2 100644 --- a/lib/WebGUI/i18n/English/WebGUI.pm +++ b/lib/WebGUI/i18n/English/WebGUI.pm @@ -3313,6 +3313,12 @@ Privileges and styles assigned to pages in the package will not be copied when t context => q|Field type name| }, + 'hidden list' => { + message => q|Hidden List|, + lastUpdated =>0, + context => q|Field type name| + }, + 'hidden' => { message => q|Hidden|, lastUpdated =>0,