More flexible required form fields (with PATCH)

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.


CheckRequiredCustomFields.txt (1.01 KB)

Ticket-Update.patch (858 Bytes)