Hi,
I'm using javascript to add a template to the description field for a JIRA issue.
Everything works fine except when you press create when you are already on the issue creation screen. A popup window appears but my description field is empty. When I am on other screens and I press create issue and the pop up appears there is no problem. The description field is populated.
Any ideas on why this might be happening?
Here is the code I use:
// Add template text to an old-style non-lightbox issue create screen
function addOldText(area) {
if (AJS.$("#issue-create-submit") == null || AJS.$("#issue-create-submit").length == 0) {
return;
}
var projectName = AJS.$("#issue-create-project-name")
if (projectName != null && projectName.length == 1) {
// innerText is Chrome only
var projectName2 = projectName[0].innerHTML;
var issueType = AJS.$("#issue-create-issue-type")
if (issueType != null && issueType.length == 1) {
var issueType2 = issueType[0].innerHTML;
}
if (projectName2 != null && issueType2 != null) {
addText(area, projectName2, issueType2);
}
}
}
// Add template text to a lightbox issue create screen
function addNewText(area) {
// Only when creating issues
if (AJS.$("#create-issue-submit") != null && AJS.$("#create-issue-submit").length != 0) {
// Find the name of the currently selected project
var projectName = AJS.$('#project-field').val();
var issueType = AJS.$('#issuetype-field').val();
addText(area, projectName, issueType);
}
}
function addText(area, projectName, issueType) {
// Add text to the description in the projectName object. The
// field may have text from a previous choice but overwrite it
// area variable is for logging.
if (projectName != null) {
templateText = "";
if (projectName == "TalentSpace Suite (HGN)" || projectName == "TalentSpace Suite" || projectName == "Careers Website" || projectName == "e360-V6" || projectName == "EPM Db" || projectName == "Foundation" || projectName == "Mobile" || projectName == "HRIS Connect" || projectName =="OAuth Server" || projectName =="Outlook Plugin") {
if (issueType == "Bug") {
// Note that both new line and line continuations are used here
var templateText = "Build number\nSite (If applicable)\nBrowser\nExpected results\nActual result\nSteps to reproduce\n\Any workaround or mitigation.\n";
}
}
console.log(AJS.$("#description").length )
if (AJS.$("#description") != null && AJS.$("#description").length > 0) {
AJS.$("#description")[0].value = templateText
}
}
}
(function($) {
AJS.toInit(function(){
// init on load
addNewText('loading')
addOldText('loading')
})
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
// init on refresh
addNewText('refreshing')
addOldText('refreshing')
});
})(AJS.$);