Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner Scripted Field: how to cleanly separate JavaScript from Groovy code?

Philip Schlesinger May 19, 2015

Hi all,

I'm writing a HTML-template ScriptRunner scripted field with a mixture of JavaScript and Groovy.  Example:

def a = 1
def b = 2
def c = 3
def output = '''
<select id="test" onChange="runMe()">
<option value="'''+a+'''">a</option>
<option value="'''+b+'''">b</option>
<option value="'''+c+'''">c</option>
</select>
<script type="text/javascript">
function runMe() {
    var selectTag = document.getElementById("test");
    var selectValue = selectTag.options[selectTag.selectedIndex].value;
    alert("my value is: "+selectValue);
}
</script>'''

IntelliJ IDEA doesn't interpret / validate / code complete any of the JavaScript because as far as it's concerned, the JavaScript is a String.

What's a clean way to separate the JavaScript from the Groovy code so when I edit the JavaScript, IntelliJ IDEA interprets / validates / code completes the JavaScript accordingly?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Philip Schlesinger June 8, 2015

Solution: 

Put HTML and JavaScript into their own files, then read those files in as strings and echo their output

0 votes
Philip Schlesinger May 27, 2015

Bump?

TAGS
AUG Leaders

Atlassian Community Events