Javascript code not working in custom field

Hi Expert,
I am using JIRA version 6.2.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>

1 answer

That's pretty big piece of code don't you think :). Can you give a hint which part does not work and explain shortly what is it supposed to do ?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

158 views 5 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you