I'm creating a Greasemonkey script to load default values for fields like "Sprint" and "Epic Link" when users create a new Issue. Currently users provide the desired text value, like "Bobs Sprint 3" and then the script is responsible for populating the field and backend HTML values.
I've had no problem with plain text fields, but the single-select and multi-select fields like "Sprint" are tricky since they AJAX load the <option> elements. I need to simulate clicking the Sprint field, wait for the JIRA AJAX options to load, then simulate clicking the proper select option. Is there some way I can hook into the AJAX events JIRA is running so I can wait for them to finish before running my triggers? Maybe through the underlying Deferreds? Here's what I've got, but the mousemove and click aren't working reliably due to the timing of GUI refreshes. I could add a setTimeout on each one but that seems really hacky:
//set raw value
AJS.$('#sprintId-field').val('Bobs Sprint 3');
//listen for the suggestions to refresh
AJS.$('#sprintId').on("suggestionsRefreshed", function(e) {
let $desiredLi = AJS.$('#sprintId-suggestions').find('li:contains(Bobs Sprint 3)');
//timing problems here!
$desiredLi.trigger('mousemove');
$desiredLi.trigger('click');
}
//trigger the suggestions load
AJS.$('#sprintId-field').trigger('click');