Mandatory custom fields

Hi all,

I am sure this was discuss before, but I could not find information about it.

How can we make a custom field, when entering a ticket via the web
interface, to be mandatory, to force the user to enter a value into it?

Thanks in advance,

Francois

This is a new feature in RT 3.5.x. The code actually isn’t too much,
and I backported it to use in my 3.4.x instance. Thankfully, it was
already setup to be used in the database so there wasn’t a change
required there as well.

This is a new feature in RT 3.5.x. The code actually isn’t too much,
and I backported it to use in my 3.4.x instance. Thankfully, it was
already setup to be used in the database so there wasn’t a change
required there as well.

Any chance you could provide diffs for 3.4.X for those of us who haven’t had a
chance to play with 3.5.X? Mandatory custom fields could provide some
useful enhancements to my RT installation.

Thanks,
Travis
Travis Campbell - Unix Systems Administrator = travis@mpdtxmail.amd.com
5900 E. Ben White Blvd, Austin, TX 78741 = travis.campbell@amd.com
TEL: (512) 602-1888 PAG: (512) 604-0341 = webmaster@mpdtxmail.amd.com
“Does anything work as expected?” Yes. An axe through the CPU.

This is a new feature in RT 3.5.x. The code actually isn’t too much,
and I backported it to use in my 3.4.x instance. Thankfully, it was
already setup to be used in the database so there wasn’t a change
required there as well.

Any chance you could provide diffs for 3.4.X for those of us who haven’t had a
chance to play with 3.5.X? Mandatory custom fields could provide some
useful enhancements to my RT installation.

You can also play with the “Chaldea” experimental branch.

Hi,

Unfortunatly this is on a production system, it would be ok to back-port a
portion of the code as Eric mentionned before, but not the whole RT beta
version…

Regards,

François

The problem is it isn’t just a straight diff. I have made several other
modifications to a lot of the files. I made further modifications for
the CF code because I didn’t like the fact that if you provided a regex,
that implied that the CF was mandatory. In other words, I wanted to be
able to say, “if you put a value in, it has to match what looks like a
year”, which is different than what is currently in the code (“you have
to enter a year value and I’ll squawk if it’s blank”).

Other problems I ran into/things I changed:

  • for select one/multiple boxes, if the field was mandatory, shouldn’t
    display “no value” (since you must have a value)
  • required custom fields show up with font in red so it’s easy to tell
    what’s required and what isn’t
  • when creating a ticket, if you didn’t provide a valid CF value, you
    would get kicked back to the creation page without an error (fixed this)
  • made sure that for a select multiple that is mandatory, you always
    have at least one value selected
  • ripped out the widget box for the validation field when modifying a
    CF. I didn’t like how the js rendered, and I figured since I am the
    only one administering it, I don’t need to have a couple to select since
    I know how to do them, so I made this a regular text field

Oh, and sorry, I misspoke about there not being a lot of changes. That
must have been some other feature I was thinking of :slight_smile: Since I can’t
provide a useable diff without including other changes I’ve made that
you may not care about, I figure the least I can do is show you the
files that I had to change:

lib/RT/CustomField_Overlay.pm # imported changes from 3.5.6 and hacked
in my changes for differentiating mandatory from non-mandatory patterns
lib/RT/CustomField.pm # straight import of new code from 3.5.6
lib/RT/CustomFieldValues.pm # straight import of new code from 3.5.6
lib/RT/CustomFields_Overlay.pm # straight import of new code from 3.5.6
lib/RT/ObjectCustomFieldValues_Overlay.pm # straight import of new code
from 3.5.6
lib/RT/ObjectCustomFieldValue_Overlay.pm # straight import of new code
from 3.5.6
share/html/Ticket/Create.html # added code from 3.5.6 and put in call
to ListActions to show CF validation errors
share/html/Admin/CustomFields/Modify.html # added code from 3.5.6, but
replaced combobox widget
share/html/Elements/EditCustomFieldSelect # added code that prevents
"no value" from being displayed if this is a mandatory CF
share/html/Elements/SelectCustomFieldValue # added code that prevents
"no value" from being displayed if this is a mandatory CF
lib/RT/Record.pm # made CF error messages clearer and unified them
share/html/Ticket/Elements/EditCustomFields # Added red font tags for
mandatory custom fields (and display a hint that red = required, but
only when there are custom fields that are red)

added from 3.5.x to 3.4.x:

lib/RT/CustomFieldValue_Overlay.pm
share/html/Elements/ValidateCustomFields

Of course, you may not need all of those changes if you don’t have my
requirements. You should be able to just get the newer versions of the
files I mentioned I got from 3.5.6, and everything will “just work” from
there.