tags:

views:

9

answers:

1

I am using a JavaScript to dynamically output a specific default text to the additional comments box in Bugzilla, based on the bug status which is selected from the drop down menu. I have tried using 'bug.bug_status' but this only changes on the submission of the page. The variable I have found which populates the drop down menu is 'bug_status.name' but when I try use this variable, it does not seem to be recognised. Has anyone any suggestions what may be causing the problem? Has anyone tried this before?

The following code has been placed at the start of the knob.html.tmpl file.

[% PROCESS global/variables.none.tmpl %]
[% # Output a specific default content in the comments box depending on bug status. %]
<script type="text/javascript">
<!--
var messages = ['Message 0', 'Message 1', 'Message 2', 'Message 3', 'Message 4',    'Message 5', 'Message 6'];
function changetext(selectObj){
   var textAreaElement = document.getElementsByName("comment")[0];
[% IF (bug_status.name == "ASSIGNED") %]
   textAreaElement.value = messages[4];
[% ELSIF(bug_status.name == "RESOLVED") %]
   textAreaElement.value = messages[5];
[% ELSE %]
   var variable1 = 0;
   variable1 = bug_status.name
   textAreaElement.value = variable1;
[% END %]
A: 

Based on your other question, it seems that you want this to change on the client side as the user is selecting a new status. However, the code that you have written in this question will change on the server side before the client sees it. Your if/else tree needs to be written in javascript instead of in Template Toolkit.

So, something like this:

function changetext(selectObj){
  var textAreaElement = document.getElementsByName("comment")[0];
  var currentStatus = document.getElementById("bug_status").value;

  if (currentStatus == "ASSIGNED") {
    textAreaElement.value = messages[4];
  } else if (currentStatus == "RESOLVED") {
    textAreaElement.value = messages[5];
  } else {
    textAreaElement.value = currentStatus;
  }
}
Scott W
Thats exactly it, thanks for your help.