diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm
index 8e188bf98..bf61b8775 100644
--- a/lib/WebGUI/Form.pm
+++ b/lib/WebGUI/Form.pm
@@ -126,13 +126,17 @@ If you want to add anything special to this form element like javascript actions
'onClick="alert(\'You've just pushed me !\')"'
+=head3 defaultValue
+
+This will be used if no value is specified.
+
=cut
sub button {
- my ($label, $extras, $subtext, $class, $output, $name, $value);
- $value = $_[0]->{value} || WebGUI::International::get(62);
+ my $params = shift;
+ my $value = $params->{value} || $params->{defaultValue} || WebGUI::International::get(62);
$value = _fixQuotes($value);
- return '{extras}.'>';
+ return '{extras}.'>';
}
#-------------------------------------------------------------------
@@ -151,7 +155,7 @@ If you'd like this box to be defaultly checked, set this to "1".
=head3 value
-The default value for this form element. Defaults to "1".
+The default value for this form element.
=head3 extras
@@ -159,13 +163,17 @@ If you want to add anything special to this form element like javascript actions
'onChange="this.form.submit()"'
+=head3 defaultValue
+
+This will be used if no value is specified. Defaults to 1.
+
=cut
sub checkbox {
- my ($checkedText, $value);
- $checkedText = ' checked="1"' if ($_[0]->{checked});
- $value = $_[0]->{value} || 1;
- return '{extras}.'>';
+ my $params = shift;
+ my $checkedText = ' checked="1"' if ($params->{checked});
+ my $value = $params->{value} || $params->{defaultValue} || 1;
+ return '{extras}.'>';
}
#-------------------------------------------------------------------
@@ -196,25 +204,31 @@ If you want to add anything special to this form element like javascript actions
'onChange="this.form.submit()"'
+=head3 defaultValue
+
+This will be used if no value is specified. Should be passed as an array reference.
+
=cut
sub checkList {
+ my $params = shift;
my ($output, $checked, $key, $item);
- foreach $key (keys %{$_[0]->{options}}) {
+ my $values = $params->{value} || $params->{defaultValue};
+ foreach $key (keys %{$params->{options}}) {
$checked = 0;
- foreach $item (@{$_[0]->{value}}) {
+ foreach $item (@{$values}) {
if ($item eq $key) {
$checked = 1;
}
}
$output .= checkbox({
- name=>$_[0]->{name},
+ name=>$params->{name},
value=>$key,
- extras=>$_[0]->{extras},
+ extras=>$params->{extras},
checked=>$checked
});
- $output .= ${$_[0]->{options}}{$key};
- if ($_[0]->{vertical}) {
+ $output .= ${$params->{options}}{$key};
+ if ($params->{vertical}) {
$output .= " \n";
} else {
$output .= " \n";
@@ -255,21 +269,25 @@ If you want to add anything special to this form element like javascript actions
'onChange="this.form.submit()"'
+=head3 defaultValue
+
+This will be used if no value is specified. Should be passed as an array reference.
+
=cut
sub combo {
- my ($output, $size);
- $_[0]->{options}->{''} = '['.WebGUI::International::get(582).']';
- $_[0]->{options}->{_new_} = WebGUI::International::get(581).'->';
- $output = selectList({
- name=>$_[0]->{name},
- options=>$_[0]->{options},
- value=>$_[0]->{value},
- multiple=>$_[0]->{multiple},
- extras=>$_[0]->{extras}
+ my $params = shift;
+ $params->{options}->{''} = '['.WebGUI::International::get(582).']';
+ $params->{options}->{_new_} = WebGUI::International::get(581).'->';
+ my $output = selectList({
+ name=>$params->{name},
+ options=>$params->{options},
+ value=>$params->{value} || $params->{defaultValue},
+ multiple=>$params->{multiple},
+ extras=>$params->{extras}
});
- $size = $session{setting}{textBoxSize}-5;
- $output .= text({name=>$_[0]->{name}."_new",size=>$size});
+ my $size = $session{setting}{textBoxSize}-5;
+ $output .= text({name=>$params->{name}."_new",size=>$size});
return $output;
}
@@ -289,7 +307,7 @@ An array reference of field types to be displayed. The types are "mixed", "html"
=head3 value
-The default value for this form element. Defaults to "mixed".
+The default value for this form element.
=head3 extras
@@ -297,9 +315,14 @@ If you want to add anything special to this form element like javascript actions
'onChange="this.form.submit()"'
+=head3 defaultValue
+
+This will be used if no value is specified. Defaults to "mixed".
+
=cut
sub contentType {
+ my $params = shift;
my (%hash, $output, $type);
tie %hash, 'Tie::IxHash';
# NOTE: What you are about to see is bad code. Do not attempt this
@@ -307,8 +330,8 @@ sub contentType {
# if/elsif construct executes much more quickly than a bunch of
# unnecessary database hits.
my @types = qw(mixed html code text);
- $_[0]->{types} = \@types unless ($_[0]->{types});
- foreach $type (@{$_[0]->{types}}) {
+ $params->{types} = \@types unless ($params->{types});
+ foreach $type (@{$params->{types}}) {
if ($type eq "text") {
$hash{text} = WebGUI::International::get(1010);
} elsif ($type eq "mixed") {
@@ -321,32 +344,38 @@ sub contentType {
}
return selectList({
options=>\%hash,
- name=>$_[0]->{name},
- value=>$_[0]->{value},
- extras=>$_[0]->{extras}
+ name=>$params->{name},
+ value=>[$params->{value}],
+ extras=>$params->{extras},
+ defaultValue=>[$params->{defaultValue}]
});
}
#-------------------------------------------------------------------
-
+
=head2 databaseLink ( hashRef )
-
+
Returns a select list of database links.
-
+
=head3 name
-
+
The name field for this form element. Defaults to "databaseLinkId".
-
+
=head3 value
-
-The unique identifier for the selected template. Defaults to "0", which is the WebGUI database.
-
+
+The unique identifier for the selected template.
+
+=head3 defaultValue
+
+This will be used if no value is specified. Defaults to 0 (the WebGUI database).
+
=cut
sub databaseLink {
- my $value = $_[0]->{value} || 0;
- my $name = $_[0]->{name} || "databaseLinkId";
+ my $params = shift;
+ my $value = $params->{value} || $params->{defaultValue} || 0;
+ my $name = $params->{name} || "databaseLinkId";
return selectList({
name=>$name,
options=>WebGUI::DatabaseLink::getList(),
@@ -387,24 +416,29 @@ The number of characters wide this form element should be. There should be no re
By default a date is placed in the "value" field. Set this to "1" to turn off the default date.
+=head3 defaultValue
+
+This will be used if no value is specified. Defaults to today.
+
=cut
sub date {
- my $value = epochToSet($_[0]->{value}) unless ($_[0]->{noDate} && $_[0]->{value} eq '');
- my $size = $_[0]->{size} || 10;
+ my $params = shift;
+ my $value = epochToSet($params->{value}||$params->{defaultValue}) unless ($params->{noDate} && $params->{value} eq '');
+ my $size = $params->{size} || 10;
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar.js',{ language=>'javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/lang/calendar-en.js',{ language=>'javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar-setup.js',{ language=>'javascript' });
WebGUI::Style::setLink($session{config}{extrasURL}.'/calendar/calendar-win2k-1.css', { rel=>"stylesheet", type=>"text/css", media=>"all" });
return text({
- name=>$_[0]->{name},
+ name=>$params->{name},
value=>$value,
size=>$size,
- extras=>'id="'.$_[0]->{name}.'Id" '.$_[0]->{extras},
+ extras=>'id="'.$params->{name}.'Id" '.$params->{extras},
maxlength=>10
}) . '