Custom Field Type and ScriptRunner's Behavior

I created a custom field type, but I found that it has problem working with ScriptRunner’s behavior.

I added a behavior to set the custom field to read-only during some workflow status.

Clicking inline edit button on the custom field opens the full edit dialog as expected. However, Jira loads the edit Velocity template of the custom field type instead of view Velocity template. I was expecting Jira to use the view template instead.

My custom field type extends GenericTextCFType, but the edit/view templates are a lot more than a simple input box. I have a input box with the custom field id as id and name (hidden from view with display: none), and this input has extra attributes “disabled” and class=“clientreadonly” attached by the behavior.

However my other input fields don’t. How can I check if the field is set to read only by ScriptRunner behavior in my edit Velocity template? I don’t want to do it with JavaScript if possible.

From this:

ScriptRunner behavior uses JavaScript to do the things it needs.

I also checked Jira’s APIs, a field being read-only seems to be never considered at all, the intended way is to exclude the field in edit mode. There’s no such property stored in any of the custom field related classes.

So the only way left is to:

  1. On page load, check if the hidden input field has class “clientreadonly”. This class is added by ScriptRunner behavior setting the field to read-only. If so, disable my other input fields.
  2. Setup a MutationObserver to monitor attribute change on the hidden input field. If class clientreadonly is added, disable my other input fields.

From my testing, it seems JavaScript for ScriptRunner behavior is executed after page load, so it is triggering the mutation observer.

I’m still working out how behavior does required. So far I only see the required class being added to the field label.