Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/lib/ObjectModel/CGI/FormPage.pm | 8 ++-- testbot/lib/ObjectModel/CGI/Page.pm | 56 ++++++++++++++++++------- testbot/lib/WineTestBot/CGI/PageBase.pm | 2 +- 3 files changed, 44 insertions(+), 22 deletions(-)
diff --git a/testbot/lib/ObjectModel/CGI/FormPage.pm b/testbot/lib/ObjectModel/CGI/FormPage.pm index 67b3fa00d3..688ee13a97 100644 --- a/testbot/lib/ObjectModel/CGI/FormPage.pm +++ b/testbot/lib/ObjectModel/CGI/FormPage.pm @@ -505,17 +505,15 @@ sub GenerateBody($) $self->GenerateFields(); $self->GenerateRequiredLegend();
- my $ErrMessage = $self->GetErrMessage(); - if (defined $ErrMessage) + if (defined $self->GetErrMessage()) { - my $ErrField = $self->GetErrField(); - if (defined $ErrField) + foreach my $ErrField (sort $self->GetErrFields()) { my $PropertyDescriptor = $self->GetPropertyDescriptorByName($ErrField); if ($PropertyDescriptor and !($self->DisplayProperty($PropertyDescriptor))[0]) { # The hidden fields should not be invalid - $self->AddError("Internal error?\n$ErrMessage", $ErrField); + $self->AddError("The hidden $ErrField field is invalid (internal error?)", $ErrField); } } $self->GenerateErrorPopup(); diff --git a/testbot/lib/ObjectModel/CGI/Page.pm b/testbot/lib/ObjectModel/CGI/Page.pm index 1d8a59fe63..37b19c8b0e 100644 --- a/testbot/lib/ObjectModel/CGI/Page.pm +++ b/testbot/lib/ObjectModel/CGI/Page.pm @@ -313,9 +313,9 @@ sub GetErrMessage($) =pod =over 12
-=head1 C<GetErrField()> +=head1 C<GetFirstErrField()>
-Returns the name of the invalid field, undef otherwise. +Returns the name of the first invalid field if any, undef otherwise.
Note that if the error does not concern a specific field this may return undef even though an error has been set. @@ -323,10 +323,29 @@ undef even though an error has been set. =back =cut
-sub GetErrField($) +sub GetFirstErrField($) { my ($self) = @_; - return $self->{ErrField}; + return $self->{ErrFields} ? (sort keys %{$self->{ErrFields}})[0] : undef; +} + +=pod +=over 12 + +=head1 C<GetErrFields()> + +Returns a list containing the names of the invalid field(s). + +Note that if the error does not concern a specific field this may return +an empty list even though an error has been set. + +=back +=cut + +sub GetErrFields($) +{ + my ($self) = @_; + return $self->{ErrFields} ? keys %{$self->{ErrFields}} : (); }
=pod @@ -334,7 +353,7 @@ sub GetErrField($)
=head1 C<IsErrField()>
-Returns true if the error concerns the specified field. +Returns true if the specified field needs to be fixed.
=back =cut @@ -342,7 +361,7 @@ Returns true if the error concerns the specified field. sub IsErrField($$) { my ($self, $FieldName) = @_; - return (defined $self->{ErrField} and $self->{ErrField} eq $FieldName); + return $self->{ErrFields}->{$FieldName}; }
=pod @@ -350,17 +369,18 @@ sub IsErrField($$)
=head1 C<AddError()>
-Sets the error message to be shown to the user. +Adds an error message to be shown to the user. =over
=item ErrMessage A message to be shown on the page that describes why the form data is invalid. This should include the display name of the field(s) that need to be fixed. -If this parameter is false the error message is not modified. +If this parameter is false, the error message and the list of invalid fields +are not modified.
-=item ErrField -If the error concerns a specific field, the name of that field. This can be -used by the page to highlight the field that needs to be corrected. +=item ErrFields +A list of field names related to the error. This can be used by the page to +highlight the field(s) that needs to be corrected.
=back
@@ -370,14 +390,18 @@ was actually added. =back =cut
-sub AddError($$;$) +sub AddError($$@) { - my ($self, $ErrMessage, $ErrField) = @_; + my $self = shift; + my $ErrMessage = shift;
if ($ErrMessage) { - $self->{ErrMessage} = $ErrMessage; - $self->{ErrField} = $ErrField; + $self->{ErrMessage} = "$self->{ErrMessage}\n$ErrMessage"; + foreach my $ErrField (@_) + { + $self->{ErrFields}->{$ErrField} = 1; + } } return $ErrMessage; } @@ -387,7 +411,7 @@ sub ResetErrors($) my ($self) = @_;
delete $self->{ErrMessage}; - delete $self->{ErrField}; + delete $self->{ErrFields}; }
sub GenerateErrorDiv($) diff --git a/testbot/lib/WineTestBot/CGI/PageBase.pm b/testbot/lib/WineTestBot/CGI/PageBase.pm index 0486bbefc2..113e6b9356 100644 --- a/testbot/lib/WineTestBot/CGI/PageBase.pm +++ b/testbot/lib/WineTestBot/CGI/PageBase.pm @@ -375,7 +375,7 @@ sub GenerateErrorPopup($$) print "<script type='text/javascript'>\n"; print "<!--\n"; print "function ShowError() { alert(", $Page->JsQuote($ErrMessage), "); }\n"; - my $ErrField = $Page->GetErrField(); + my $ErrField = $Page->GetFirstErrField(); if ($ErrField) { print "document.forms[0].", $ErrField, ".focus();\n";