Fix handling of multi-form and multiple select form elements by emitting

a hidden form variable to make sure the form element was in the generated form.
Changes in User and ProfileField to support this.
This commit is contained in:
Colin Kuskie 2009-01-26 21:03:23 +00:00
parent 83d1203de9
commit 41da738e0e
9 changed files with 134 additions and 17 deletions

View file

@ -18,6 +18,7 @@ use strict;
use base 'WebGUI::Form::List';
use WebGUI::Form::Checkbox;
use WebGUI::Form::Button;
use WebGUI::Form::Hidden;
use WebGUI::International;
=head1 NAME
@ -129,6 +130,18 @@ sub isDynamicCompatible {
#-------------------------------------------------------------------
=head2 isInRequest ( )
=cut
sub isInRequest {
my $self = shift;
my $form = $self->session->form;
return $form->hasParam($self->privateName('isIn'));
}
#-------------------------------------------------------------------
=head2 toHtml ( )
Renders a series of checkboxes.
@ -136,8 +149,10 @@ Renders a series of checkboxes.
=cut
sub toHtml {
my $self = shift;
my $self = shift;
my $session = $self->session;
my $output = '<fieldset style="border:none;margin:0;padding:0">';
$output .= WebGUI::Form::Hidden($session, { name => $self->privateName('isIn'), value => 1, });
my $alignment = $self->alignmentSeparator;
# Add the select all button
@ -153,7 +168,7 @@ sub toHtml {
? 1
: 0
;
$output .= WebGUI::Form::Checkbox->new($self->session, {
$output .= WebGUI::Form::Checkbox->new($session, {
name => $self->get('name'),
value => $key,
extras => $self->get('extras'),

View file

@ -419,7 +419,7 @@ sub getOriginalValue {
=head2 getDefaultValue ( )
Returns the "defaultValue" passed in to the object in that order
Returns the "defaultValue".
=cut
@ -454,10 +454,8 @@ Depricated. See getValue().
# getValueFromPost is deprecated, use getValue
sub getValueFromPost {
my $self = shift;
if ($self->session->request) {
my $value = $self->session->form->param($self->get("name"));
return $value if (defined $value);
}
my $value = $self->session->form->param($self->get("name"));
return $value if (defined $value);
return $self->getDefaultValue;
}
@ -475,6 +473,25 @@ sub isDynamicCompatible {
#-------------------------------------------------------------------
=head2 isInRequest ( )
Object method that returns true if the form variables for this control exist in the
posted data from the client. This is required for all controls that are dynamic
compatible (->isDynamicCompatible=1). It should be overridden by any class that
changes the name of the form variable, or uses more than 1 named element per form.
This method should only depend on the form name, and not secondary form properties
such as value, defaultValue or storage or asset id's.
=cut
sub isInRequest {
my $self = shift;
return $self->session->form->hasParam($self->get('name'));
}
#-------------------------------------------------------------------
=head2 isProfileEnabled ( session )
Depricated. See isDynamicCompatible().
@ -484,7 +501,6 @@ Depricated. See isDynamicCompatible().
sub isProfileEnabled {
my $class = shift;
my $session = shift;
return $class->isDynamicCompatible();
}

View file

@ -240,6 +240,21 @@ sub isDynamicCompatible {
#-------------------------------------------------------------------
=head2 isInRequest ( )
=cut
sub isInRequest {
my $self = shift;
my $form = $self->session->form;
my $name = $self->get('name');
my $isInRequest = $form->hasParam($name.'_file')
|| $form->hasParam($self->privateName('action'));
return $isInRequest;
}
#-------------------------------------------------------------------
=head2 toHtml ( )
Renders a file upload control.

View file

@ -143,6 +143,20 @@ sub isDynamicCompatible {
#-------------------------------------------------------------------
=head2 isInRequest ( )
=cut
sub isInRequest {
my $self = shift;
my $form = $self->session->form;
my $name = $self->get('name');
return $form->hasParam($name.'_interval')
|| $form->hasParam($name.'_units');
}
#-------------------------------------------------------------------
=head2 toHtml ( )
Renders an interval control.

View file

@ -98,6 +98,19 @@ sub isDynamicCompatible {
#-------------------------------------------------------------------
=head2 isInRequest ( )
=cut
sub isInRequest {
my $self = shift;
my $form = $self->session->form;
return $form->hasParam($self->privateName('isIn'));
}
#-------------------------------------------------------------------
=head2 toHtml ( )
Renders a select list form control.
@ -105,9 +118,10 @@ Renders a select list form control.
=cut
sub toHtml {
my $self = shift;
my $self = shift;
my $session = $self->session;
my $multiple = $self->get("multiple") ? ' multiple="multiple"' : '';
my $output = '<select name="'.($self->get("name")||'').'" size="'.($self->get("size")||'').'" id="'.($self->get('id')||'').'" '.($self->get("extras")||'').$multiple.'>';
my $output = '<select name="'.($self->get("name")||'').'" size="'.($self->get("size")||'').'" id="'.($self->get('id')||'').'" '.($self->get("extras")||'').$multiple.'>';
my $options = $self->getOptions;
my @values = $self->getOriginalValue();
foreach my $key (keys %{$options}) {
@ -120,6 +134,7 @@ sub toHtml {
$output .= '>'.$options->{$key}.'</option>';
}
$output .= '</select>'."\n";
$output .= WebGUI::Form::Hidden($session, { name => $self->privateName('isIn'), value => 1, });
return $output;
}