[rt-users] ValidateCustomFields
Wolfram Huettermann
wolfram.huettermann at desy.de
Tue Oct 23 05:03:47 EDT 2012
On 10/22/12 18:00, rt-users-request at lists.bestpractical.com wrote:
> Send rt-users mailing list submissions to
> rt-users at lists.bestpractical.com
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
> or, via email, send a message with subject or body 'help' to
> rt-users-request at lists.bestpractical.com
>
> You can reach the person managing the list at
> rt-users-owner at lists.bestpractical.com
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of rt-users digest..."
>
>
> Today's Topics:
>
> 1. Friendly Validation Errors? (Mike Kennedy)
> 2. Re: Size of the database. (Darin Perusich)
> 3. RT-Authen-ExternalAuth. (Julien CAUNAN)
> 4. Re: Size of the database. (Albert Shih)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 22 Oct 2012 03:27:45 +0000
> From: Mike Kennedy<michael.kennedy at ucr.edu>
> To: ""
> <rt-users at lists.bestpractical.com>
> Subject: [rt-users] Friendly Validation Errors?
> Message-ID:
> <4377A360F69D024197AF65862DEBCC051FE0C5B1 at EXCH-MBOX-1.exch.ucr.edu>
> Content-Type: text/plain; charset="us-ascii"
>
> Hello,
>
> I've searched the archives, Google, the wiki (so I'm sorry if the answer to this is there, but I just missed it.)
>
> Is there any way, short of editing the source, to have more friendly validation errors. So, rather than "Input must match [Mandatory]" I could change it to say "This field is required." Or, instead of "Input must match ^[a-zA-Z]+$", it could say, "Value must contain only letters."
>
> Thanks,
>
> Mike
>
>
>
>
Hello Mike,
you can change /Elements/ValidateCustomFields in a plugin like that that.
The code is like that:
my %Messages = ("[Mandatory]" => "This field is required",
"[^[a-zA-Z]+]" => "This field must contain letters");
foreach my $value( @values ) {
next if $CF->MatchPattern($value);
my $msg = exists($Messages{$CF->FriendlyPattern})
?$Messages{$CF->FriendlyPattern} :"Input must match".$CF->FriendlyPattern ;
$m->notes( ('InvalidField-' . $CF->Id) => $msg );
push @res, $msg;
$valid = 0;
}
That does work.
More information about the rt-users
mailing list