Run a JavaScript Validator (or anything) on Document Load Event? RTC 5.0.2
dojo.provide("thisCode");dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("com.ibm.team.workitem.api.common.Status");(function() {var Status = com.ibm.team.workitem.api.common.Status;dojo.declare("thisCode", null, {validate: function(attribute, workItem, configuration) {document.onload = function() {var defectSource = workItem.getLabel("defect.source");var targetDOMelement = document.querySelector("input[aria-labelledby='Special Number']");if (defectSource === "Internal") {targetDOMelement.setAttribute("disabled", "");return;}}return Status.OK_STATUS;}});})();
2 answers
https://jazz.net/wiki/bin/view/Main/AttributeCustomization
a more extensive workshop can be found here:
where Lab 5 explains JavaScript.
If you want to make a work item attribute read only based on some other work item attribute, you should use a condition and not a validator. Also see https://rsjazz.wordpress.com/2015/06/19/a-custom-condition-to-make-attributes-required-or-read-only-by-role/ for a more extreme case.
I have never tried to get a document property and change it in the attribute customization. It may not be a good idea.
Comments
Attribute customization can not be used to directly write to any object. You can only return values. If the attribute customization is a calculated or default value, and the value returned is a valid value, this can change the attribute. Otherwise you can NOT change anything in an attribute customization.
Since Attribute customization runs in the Eclipse Client in the Web Client and partially in the Jazz Server (conditions, validators), you can not assume to be able to use the full event mechanisms or other values provided by the web browser.
Have you even tried to use a condition? I don't think so and I think you should. You are making conclusions on something you have not yet well understood.
The condition essentially switches the editor presentation read only dynamically and the user can basically see that he can't enter anything any more, as soon as the condition says so. Changing the input value, would make the field read only at that point.