From 299850f765aa06dfc965c779e7fdd6f6ccf5d786 Mon Sep 17 00:00:00 2001 From: davidblasby <48937730+davidblasby@users.noreply.github.com> Date: Mon, 15 Jun 2020 08:43:22 -0700 Subject: [PATCH] UX keyword chooser - enter key (#4735) * UX keyword chooser - enter key * more UX improvements Co-authored-by: david blasby --- .../thesaurus/ThesaurusDirective.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/web-ui/src/main/resources/catalog/components/thesaurus/ThesaurusDirective.js b/web-ui/src/main/resources/catalog/components/thesaurus/ThesaurusDirective.js index 8855ac0a332..ec941a6fc86 100644 --- a/web-ui/src/main/resources/catalog/components/thesaurus/ThesaurusDirective.js +++ b/web-ui/src/main/resources/catalog/components/thesaurus/ThesaurusDirective.js @@ -419,8 +419,42 @@ // Clear typeahead this.tagsinput('input').typeahead('val', ''); + field.blur(); + field.triggerHandler('input'); // force angular to see changes }, $(id)) ); + // UX improvement + // When the user presses "enter", allow the item to be selected + field.bind("keydown keypress", function(event){ + if (event.isDefaultPrevented()) { + event.stopPropagation(); // need to prevent this from bubbling - or something might action it + field.focus(); //allow to type again + return false; //this event has already been handled by tt-typeahead, dont do it twice! + } + if (event.keyCode ==13) { // pressed "enter" + event.stopPropagation(); // we are handling the event... + event.preventDefault(); + if (element.find(".tt-selectable").length <1) + return; // should be an element (keyword choice) visible + var val = element.find(".tt-selectable").first().text(); //first one + if ( (!val) || (val == '')) + return; // no value, nothing to do + + //get full keyword info from server + gnThesaurusService.getKeywords(val, + scope.thesaurusKey, gnLangs.current, 1, 'MATCH') + .then(function(listOfKeywords) { + if (listOfKeywords.length == 1) { // should be one match + field.typeahead().trigger("typeahead:selected", listOfKeywords[0],listOfKeywords[0]); + field.typeahead('close'); + field.focus(); //allow to type again + field.triggerHandler('input'); // force angular to see changes + } + } + ); + + } + }); $(id).on('itemRemoved', function() { angular.copy($(this)