Skip to content

Commit 299850f

Browse files
UX keyword chooser - enter key (geonetwork#4735)
* UX keyword chooser - enter key * more UX improvements Co-authored-by: david blasby <[email protected]>
1 parent 8dae1a1 commit 299850f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

web-ui/src/main/resources/catalog/components/thesaurus/ThesaurusDirective.js

+34
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,42 @@
419419

420420
// Clear typeahead
421421
this.tagsinput('input').typeahead('val', '');
422+
field.blur();
423+
field.triggerHandler('input'); // force angular to see changes
422424
}, $(id))
423425
);
426+
// UX improvement
427+
// When the user presses "enter", allow the item to be selected
428+
field.bind("keydown keypress", function(event){
429+
if (event.isDefaultPrevented()) {
430+
event.stopPropagation(); // need to prevent this from bubbling - or something might action it
431+
field.focus(); //allow to type again
432+
return false; //this event has already been handled by tt-typeahead, dont do it twice!
433+
}
434+
if (event.keyCode ==13) { // pressed "enter"
435+
event.stopPropagation(); // we are handling the event...
436+
event.preventDefault();
437+
if (element.find(".tt-selectable").length <1)
438+
return; // should be an element (keyword choice) visible
439+
var val = element.find(".tt-selectable").first().text(); //first one
440+
if ( (!val) || (val == ''))
441+
return; // no value, nothing to do
442+
443+
//get full keyword info from server
444+
gnThesaurusService.getKeywords(val,
445+
scope.thesaurusKey, gnLangs.current, 1, 'MATCH')
446+
.then(function(listOfKeywords) {
447+
if (listOfKeywords.length == 1) { // should be one match
448+
field.typeahead().trigger("typeahead:selected", listOfKeywords[0],listOfKeywords[0]);
449+
field.typeahead('close');
450+
field.focus(); //allow to type again
451+
field.triggerHandler('input'); // force angular to see changes
452+
}
453+
}
454+
);
455+
456+
}
457+
});
424458

425459
$(id).on('itemRemoved', function() {
426460
angular.copy($(this)

0 commit comments

Comments
 (0)