Javascript not working in custom fields

Mohin Uddin March 16, 2014

Hi Expert,
I am using JIRA version 4.0.2 currently I am using some java script code to one custom field.At before It worked fine but now it does not working.

Could you please check this issue and let us know the solution.

codes are given below:

<script type="text/javascript">

 

if (typeof(CustomTextFiller) == "undefined") {

var CustomTextFiller = new Class({

Implements: Options,

options: {

textareaId: "",

values:[]

},

initialize: function (options) {

this.setOptions(options);

 

this.textarea = document.id(this.options.textareaId);

 

if (!this.textarea && console)

console.log("CustomTextFiller[" + this.options.textareaId + "]: Textarea not found!");

 

if (this.options.values.length == 0 && console)

console.log("CustomTextFiller[" + this.options.textareaId + "]: No values specified!");

 

var isNewRecord = true;

var formTitles = $$("h3.formtitle");

for (var i = 0; i < formTitles.length; i++) {

if (formTitles[i].get("text").trim() == "Edit Issue") {

isNewRecord = false;

break;

}

}

 

if (!isNewRecord)

console.log("CustomTextFiller[" + this.options.textareaId + "]: Not a redo request!");

 

 

if (this.textarea && this.options.values.length > 0 && isNewRecord) {

 

this.cycle = this.getCycle();

 

this.appendLine("[BEGIN_CYCLE_" + this.cycle + "]");

 

for (var i = 0; i < this.options.values.length; i++) {

var item = this.options.values[i];

var x = item.split(/:0:/g);

var key = x[0];

var value = x.length > 1 ? x[1] : "Undefined";

var div = this.createCheckboxDiv(key, value);

div.inject(this.textarea, "before");

}

 

var otherDiv = this.createOtherCheckboxTextboxDiv();

otherDiv.inject(this.textarea, "before");

 

if (console)

console.log("CustomTextFiller[" + this.options.textareaId + "]: Loaded successfully.");

} else {

if (console)

console.log("CustomTextFiller[" + this.options.textareaId + "]: Not loaded.");

}

},

getCycle: function(){

var cycle = -1;

 

if (this.textarea) {

var regex =  /\[BEGIN_CYCLE_(\d*)\]/g;

var match = null;

 

while((match = regex.exec(this.textarea.value)) != null)

{

var x = parseInt(match[1], 10);

 

if (typeof(x) == "number" && x > cycle) {

cycle = x;

 

if (console)

console.log("CustomTextFiller[" + this.options.textareaId + "]: Update cycle to " + x + ".");

}

}

}

 

return cycle + 1;

},

createCheckboxDiv: function(key, value) {

var checkbox = new Element("input", {

type: "checkbox",

id: this.options.textareaId + "_" + key,

value: value

});

 

checkbox.set("key", key);

checkbox.set("value", value);

 

checkbox.addEvent("click", function(){

var line = checkbox.get("key") + ":" + this.cycle + ":" + checkbox.get("value");

if (checkbox.checked)

this.appendLine(line);

else

this.removeLine(line);

 

this.textarea.focus();

this.checkbox.focus();

}.bind(this));

 

var label = new Element("label", {

"for" : this.options.textareaId + "_" + key,

html : value

});

 

var div = new Element("div");

div.grab(checkbox);

div.appendText(" ");

div.grab(label);

 

return div;

},

createOtherCheckboxTextboxDiv: function() {

var checkbox = new Element("input", {

type: "checkbox",

id: this.options.textareaId + "_OTHER",

value: "OTHER"

});

 

var textbox = new Element("input", {

type: "text",

id: this.options.textareaId + "_OTHER_value"

});

 

checkbox.addEvent("click", function(e){

if (textbox.value.trim().length == 0) {

alert("Please enter problem description first!");

e.stop();

} else {

var line = "OTHER:" + this.cycle + ":" + textbox.get("value");

if (checkbox.checked) {

textbox.setProperty("readonly", "readonly")

this.appendLine(line);

} else {

this.removeLine(line);

textbox.setProperty("readonly", "")

}

 

this.textarea.focus();

this.checkbox.focus();

}

}.bind(this));

 

var label = new Element("label", {

"for" : this.options.textareaId + "_OTHER",

 

 

 

 

html : "Others"

});

 

var div = new Element("div");

div.grab(checkbox);

div.appendText(" ");

div.grab(label);

div.appendText(" ");

div.grab(textbox);

 

return div;

},

appendLine: function(line){

if (this.textarea) {

var lb = window.ie ? "\r\n" : "\n";

if (this.textarea.value.trim().length > 0)

this.textarea.value = this.textarea.value.trim() + lb + line;

else

this.textarea.value = line;

}

 

if (console)

console.log("CustomTextFiller[" + this.options.textareaId + "]: Append \"" + line + "\".");

 

},

removeLine: function(line){

if (this.textarea && this.textarea.value.trim().length > 0) {

var regexText = window.ie ? "\r\n" + line : "\n" + line;

var regex = new RegExp(regexText.escapeRegExp(), "g");

this.textarea.value = this.textarea.value.trim().replace(regex, "");

}

 

if (console)

console.log("CustomTextFiller[" + this.options.textareaId + "]: Remove \"" + line + "\".");

}

});

}

 

window.addEvent("domready", function() {

var customfield_11695 = new CustomTextFiller({

textareaId: "customfield_11695",

values:[

"New/Changed Functionality:0:New/Changed Functionality",

"Creative Asset Delay:0:Creative Asset Delay",

"GMIT:0:GMIT",

"Bug Fixing:0:Bug Fixing",

"Production Capacity:0:Production Capacity",

"Brand/Legal delay:0:Brand/Legal delay"

]

});

});

</script><font color="red">Please specify the change requirements/details (at every revision round) in the comments box below.</font>

Thanks

Mohin

5 answers

0 votes
Mohin Uddin March 18, 2014

Thanks Boris Georgiev.We didn't anu kind of change this code at before.

0 votes
Mohin Uddin March 17, 2014

the error says "Uncaught ReferenceError: Class is not defined"

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2014

Obviously there is no Class Javascript object. What have you changed before this code stopped working? Have you changed the version of JIRA or something else in the code ?

0 votes
Mohin Uddin March 17, 2014

Thnx for the information.

I have already running in the Chrome browser console and find a syntax error.

So,that how can I resolve this?

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2014

What does the error says ?

0 votes
Mohin Uddin March 17, 2014

We are using the above javascript code for six check box fields and those were appearing perfectly currently those fields are not working.

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2014

Are there any JS errors in the borwser console? Try running this with Chrome and look at the Console (F12)

0 votes
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 16, 2014

Would you give some more information - What exactly isn't working as this is pretty long JS snippet :)

Suggest an answer

Log in or Sign up to answer