Javascript not working in custom fields

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

This widget could not be displayed.

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

This widget could not be displayed.

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

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

This widget could not be displayed.

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?

What does the error says ?

This widget could not be displayed.

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

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 ?

This widget could not be displayed.

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

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

576 views 25 15
Join discussion

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