[Rt-devel] More flexible required form fields (with PATCH)

Drew Taylor DTaylor at cidc.com
Fri Jul 28 14:37:21 EDT 2006

Hi everyone,
In my continuing adventures with RT (mostly very happy) I've run into a
situation with needing to make custom fields be required in ONLY
specific circumstances. For instance, I have a CF "Internal Email
Address" has no Pattern assigned. However, when resolving/rejecting a
particular type of ticket I want to make it required. A callback for
/Ticket/Update.html within <%INIT> (like Display.html) and a check for
$m->notes("ValidFields") seems to be in order to allow this to happen
flexibly. In conjunction with the above change, I copied
/Elements/ValidateCustomFields (which uses the ValidFields note) as
/Elements/CheckRequiredCustomFields, and modified it to take an array of
CustomField objects rather than a CustomFields object and checks that
there is a form value for each one in the list. 

How it all works: I created the Initial callback component for
/Ticket/Update.html. This in turn checks if it should be running, and
then calls /Elements/CheckRequiredCustomFields.
CheckRequiredCustomFields returns a boolean (1 if all present, 0 if any
missing), and this is return value is stored in
$m->notes("ValidFields"). Finally Update.html looks for a true value in
this note before sending processing to Display.html. No Display.html ==
no saves to database.

Attached is my CheckRequiredCustomFields file and a trivial patch to
/Ticket/Update.html. Feel free to incorporate this into RT if you find
it useful. One thing that I find somewhat lacking in RT is the ability
to specify required fields. The Pattern for Custom Fields goes partway
to achieving this goal, but it doesn't address the standard Ticket
fields at all. A few more Callbacks, with perhaps a documented and/or
universal use of $m->notes("ValidFields"), would go along way to making
it possible.


-------------- next part --------------
## /Elements/CheckRequiredCustomFields

## Copied from /Elements/ValidateCustomFields
my $valid = 1;
foreach my $CF (@CustomFields) {
    my $field = $NamePrefix . $CF->Id . "-Value";
    my $value;

    if ($ARGSRef->{"${field}s-Magic"} and exists $ARGSRef->{"${field}s"}) {
        $value = $ARGSRef->{"${field}s"};

        # We only validate Single Combos -- multis can never be user input
        $RT::Logger->debug("CheckRequiredCustomFields: multiple input values!");
        next if ref $value;
    else {
        $value = $ARGSRef->{$field};

    $m->notes('Field-' . $CF->Id => $value);
    $RT::Logger->debug("CheckRequiredCustomFields: [".$CF->Id."] Value [$value]");
    next if $value; # entering a "true" value is sufficient

    $m->notes( 'InvalidField-' . $CF->Id => loc("Input is required") );
    $valid = 0;
$m->notes('RequiredFields', $valid);
return $valid;

$NamePrefix => "Object-RT::Ticket--CustomField-"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Ticket-Update.patch
Type: application/octet-stream
Size: 858 bytes
Desc: Ticket-Update.patch
Url : http://lists.bestpractical.com/pipermail/rt-devel/attachments/20060728/0ea66263/Ticket-Update.obj

More information about the Rt-devel mailing list