The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript code not working in custom field

Mohin Uddin
Contributor
April 16, 2014

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

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 Champions.
April 16, 2014

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 ?

TAGS
AUG Leaders

Atlassian Community Events