added the hidden list field type

This commit is contained in:
JT Smith 2005-07-26 21:54:47 +00:00
parent 6ebf9c9ff3
commit c15cfa954f
6 changed files with 190 additions and 196 deletions

View file

@ -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";
}
#-------------------------------------------------------------------

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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,