clear any event listener added in previous invocation of this function

This commit is contained in:
zadam 2020-10-02 21:44:21 +02:00
parent 5e2077e6ae
commit a9a9edf658
2 changed files with 6 additions and 2 deletions

View File

@ -13,8 +13,6 @@ export async function showDialog() {
utils.openDialog($dialog);
noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true })
// clear any event listener added in previous invocation of this function
.off('autocomplete:noteselected')
.on('autocomplete:noteselected', function(event, suggestion, dataset) {
if (!suggestion.notePath) {
return false;

View File

@ -67,6 +67,9 @@ function showRecentNotes($el) {
function initNoteAutocomplete($el, options) {
if ($el.hasClass("note-autocomplete-input") || utils.isMobile()) {
// clear any event listener added in previous invocation of this function
$el.off('autocomplete:noteselected');
return $el;
}
@ -157,6 +160,9 @@ function initNoteAutocomplete($el, options) {
}
});
// clear any event listener added in previous invocation of this function
$el.off('autocomplete:noteselected');
return $el;
}