Skip to content

Commit

Permalink
Merge branch '5.0/validate-cfs-custom-labels' into 5.0-trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrandtbuffalo committed Nov 14, 2023
2 parents 16991a0 + 3ec758e commit 19d55bf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions share/html/Elements/ValidateCustomFields
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ while ( my $CF = $CustomFields->Next ) {

$m->notes(('Field-' . $CF->Id) => $submitted->{Values} // $submitted->{Value});

# Validation messages can display an alternate label if the RT UI
# shows something other than the default CF Name. To use a different
# label, provide %Labels with the CF name as the key and the alternate
# label as the value.

my $label = $Labels{$CF->Name} || $CF->Name;
if ( $invalid ) {
$m->notes( 'InvalidField-' . $CF->Id => $invalid_message );
push @res, $CF->Name . ': ' . $invalid_message;
push @res, $label . ': ' . $invalid_message;
$valid = 0;
next;
}
Expand Down Expand Up @@ -112,15 +118,15 @@ while ( my $CF = $CustomFields->Next ) {
my ($ok, $msg) = $CF->_CanonicalizeValue( $ref );
unless ($ok) {
$m->notes( ( 'InvalidField-' . $CF->Id ) => $msg );
push @res, $CF->Name .': '. $msg;
push @res, $label . ': ' . $msg;
$valid = 0;
}
}

if (!$CF->MatchPattern($value)) {
my $msg = $CF->FriendlyPattern;
$m->notes( ('InvalidField-' . $CF->Id) => $msg );
push @res, $CF->Name .': '. $msg;
push @res, $label . ': ' . $msg;
$valid = 0;
}

Expand All @@ -138,7 +144,7 @@ while ( my $CF = $CustomFields->Next ) {
while (my $ocfv = $existing->Next) {
my $msg = loc("'[_1]' is not a unique value", $value);
$m->notes( ('InvalidField-' . $CF->Id) => $msg );
push @res, $CF->Name .': '. $msg;
push @res, $label . ': ' . $msg;
$valid = 0;
last;
}
Expand All @@ -153,4 +159,5 @@ $Object => RT::Ticket->new( $session{'CurrentUser'})
$CustomFields
$ARGSRef
$ValidateUnsubmitted => 0
%Labels => () # Optional hash of alternate labels for CFs
</%ARGS>

0 comments on commit 19d55bf

Please sign in to comment.