|
419 | 419 |
|
420 | 420 | // Clear typeahead
|
421 | 421 | this.tagsinput('input').typeahead('val', '');
|
| 422 | + field.blur(); |
| 423 | + field.triggerHandler('input'); // force angular to see changes |
422 | 424 | }, $(id))
|
423 | 425 | );
|
| 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 | + }); |
424 | 458 |
|
425 | 459 | $(id).on('itemRemoved', function() {
|
426 | 460 | angular.copy($(this)
|
|
0 commit comments