[Rt-commit] r8052 - rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Elements
ruz at bestpractical.com
ruz at bestpractical.com
Tue Jul 3 06:19:22 EDT 2007
Author: ruz
Date: Tue Jul 3 06:16:34 2007
New Revision: 8052
Modified:
rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Elements/ValidateCustomFields
Log:
* validate multiple values each on its own, use the same logicfor splitting
as we do in Interface::Web
Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Elements/ValidateCustomFields
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Elements/ValidateCustomFields (original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/html/Elements/ValidateCustomFields Tue Jul 3 06:16:34 2007
@@ -50,8 +50,8 @@
$CustomFields->GotoFirstItem;
while ( my $CF = $CustomFields->Next ) {
my $field = $NamePrefix . $CF->Id . "-Value";
- my $value;
+ my $value;
if ($ARGSRef->{"${field}s-Magic"} and exists $ARGSRef->{"${field}s"}) {
$value = $ARGSRef->{"${field}s"};
@@ -61,14 +61,34 @@
else {
$value = $ARGSRef->{$field};
}
-
$m->notes(('Field-' . $CF->Id) => $value);
- next if $CF->MatchPattern($value);
- my $msg = loc("Input must match [_1]", $CF->FriendlyPattern);
- $m->notes( ('InvalidField-' . $CF->Id) => $msg );
- push @res, $msg;
- $valid = 0;
+ my @values = ();
+ if ( ref $value eq 'ARRAY' ) {
+ @values = @$value;
+ } elsif ( $CF->Type =~ /text/i ) {
+ @values = ($value);
+ } else {
+ @values = split /\r*\n/, $value;
+ }
+ @values = grep $_ ne '',
+ map {
+ s/\r+\n/\n/g;
+ s/^\s+//;
+ s/\s+$//;
+ $_;
+ }
+ grep defined, @values;
+ @values = ('') unless @values;
+
+ foreach my $value( @values ) {
+ next if $CF->MatchPattern($value);
+
+ my $msg = loc("Input must match [_1]", $CF->FriendlyPattern);
+ $m->notes( ('InvalidField-' . $CF->Id) => $msg );
+ push @res, $msg;
+ $valid = 0;
+ }
}
$m->notes('ValidFields', $valid);
return wantarray? ($valid, @res): $valid;
More information about the Rt-commit
mailing list