Feature #2500 » dynamic-mandatory-issue-field.js
| 1 |
// When the Status field is set to "Done", check that the Resolution field is not empty
|
|---|---|
| 2 |
|
| 3 |
var k_resolutionFieldId = "issue_custom_field_values_14"; |
| 4 |
|
| 5 |
// Our status are "New" and "Done"
|
| 6 |
function isIssueStatusNew() |
| 7 |
{
|
| 8 |
var elt = document.getElementById("issue_status_id"); |
| 9 |
if( elt.selectedIndex == -1 |
| 10 |
|| elt.options[elt.selectedIndex].text == "New" ) |
| 11 |
{
|
| 12 |
return true; |
| 13 |
}
|
| 14 |
return false; |
| 15 |
}
|
| 16 |
|
| 17 |
function onSubmit(e) |
| 18 |
{
|
| 19 |
var selectStatus = document.getElementById("issue_status_id"); |
| 20 |
if( selectStatus == null ) |
| 21 |
{
|
| 22 |
// No status field
|
| 23 |
return; |
| 24 |
}
|
| 25 |
var selectResol = document.getElementById(k_resolutionFieldId); |
| 26 |
if( selectResol == null ) |
| 27 |
{
|
| 28 |
// No Resolution field
|
| 29 |
return; |
| 30 |
}
|
| 31 |
if( isIssueStatusNew() ) |
| 32 |
{
|
| 33 |
// "New" status, no check needed
|
| 34 |
return; |
| 35 |
}
|
| 36 |
|
| 37 |
if( selectResol.selectedIndex == -1 || |
| 38 |
selectResol.options[selectResol.selectedIndex].text == "" ) |
| 39 |
{
|
| 40 |
// Resolution missing
|
| 41 |
alert("Please set Resolution"); |
| 42 |
e.preventDefault(); |
| 43 |
return; |
| 44 |
}
|
| 45 |
}
|
| 46 |
|
| 47 |
function onDocumentLoaded() |
| 48 |
{
|
| 49 |
// If this is not an issue form, do nothing
|
| 50 |
var form = document.getElementById("issue-form") |
| 51 |
if( form == null ) |
| 52 |
{
|
| 53 |
return; // Other page |
| 54 |
}
|
| 55 |
Event.observe(form, "submit", onSubmit); |
| 56 |
}
|
| 57 |
|
| 58 |
Event.observe(window, 'load', onDocumentLoaded); |