From 7ad788a602c328f5f94beb7252dd8261749d5d1d Mon Sep 17 00:00:00 2001 From: Chris Schmitz Date: Mon, 3 Aug 2015 16:09:37 -0500 Subject: [PATCH] Don't auto close results when pressing enter --- angucomplete-alt.js | 5 +---- dist/angucomplete-alt.min.js | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/angucomplete-alt.js b/angucomplete-alt.js index 8d5156ca..f4d67775 100644 --- a/angucomplete-alt.js +++ b/angucomplete-alt.js @@ -326,11 +326,8 @@ if (scope.currentIndex >= 0 && scope.currentIndex < scope.results.length) { event.preventDefault(); scope.selectResult(scope.results[scope.currentIndex]); - } else { - handleOverrideSuggestions(event); - clearResults(); + scope.$apply(); } - scope.$apply(); } else if (which === KEY_DW && scope.results) { event.preventDefault(); if ((scope.currentIndex + 1) < scope.results.length && scope.showDropdown) { diff --git a/dist/angucomplete-alt.min.js b/dist/angucomplete-alt.min.js index 4a01ecd8..8c1d786f 100644 --- a/dist/angucomplete-alt.min.js +++ b/dist/angucomplete-alt.min.js @@ -1,2 +1,2 @@ /*! Copyright (c) 2014 Hidenari Nozaki and contributors | Licensed under the MIT license */ -"use strict";!function(a,b){"undefined"!=typeof module&&module.exports?module.exports=b(require("angular")):"function"==typeof define&&define.amd?define(["angular"],b):b(a.angular)}(window,function(a){a.module("angucomplete-alt",[]).directive("angucompleteAlt",["$q","$parse","$http","$sce","$timeout","$templateCache","$interpolate",function(a,b,c,d,e,f,g){function h(b,f,g,h){function w(a){la=null,b.hideResults(a),document.body.removeEventListener("click",w)}function x(a){return a.which?a.which:a.keyCode}function y(a){"function"==typeof b.selectedObject?b.selectedObject(a):b.selectedObject=a,E(a?!0:!1)}function z(a){return function(c){return b[a]?b[a](c):c}}function A(a){y({originalObject:a}),b.clearSelected&&(b.searchStr=null),T()}function B(a){return b.titleField.split(",").map(function(b){return C(a,b)}).join(" ")}function C(a,b){var c,d;if(b){c=b.split("."),d=a;for(var e=0;e'+f[0]+""):a,d.trustAsHtml(e)):void 0}function E(a){b.notEmpty=a,ha=b.searchStr,b.fieldRequired&&h&&h.$setValidity(ga,a)}function F(a){var c=x(a);if(c!==l&&c!==j)if(c===k||c===n)a.preventDefault();else if(c===i)a.preventDefault(),!b.showDropdown&&b.searchStr&&b.searchStr.length>=ea&&(U(),b.searching=!0,X(b.searchStr));else if(c===m)T(),b.$apply(function(){da.val(b.searchStr)});else{if(0===ea&&!b.searchStr)return;b.searchStr&&""!==b.searchStr?b.searchStr.length>=ea&&(U(),fa&&e.cancel(fa),b.searching=!0,fa=e(function(){X(b.searchStr)},b.pause)):b.showDropdown=!1,ha&&ha!==b.searchStr&&!b.clearSelected&&b.$apply(function(){y()})}}function G(a){!b.overrideSuggestions||b.selectedObject&&b.selectedObject.originalObject===b.searchStr||(a&&a.preventDefault(),A(b.searchStr))}function H(a){var b=getComputedStyle(a);return a.offsetHeight+parseInt(b.marginTop,10)+parseInt(b.marginBottom,10)}function I(){return ja.getBoundingClientRect().top+parseInt(getComputedStyle(ja).maxHeight,10)}function J(){return f[0].querySelectorAll(".angucomplete-row")[b.currentIndex]}function K(){return J().getBoundingClientRect().top-(ja.getBoundingClientRect().top+parseInt(getComputedStyle(ja).paddingTop,10))}function L(a){ja.scrollTop=ja.scrollTop+a}function M(){var a=b.results[b.currentIndex];b.matchClass?da.val(B(a.originalObject)):da.val(a.title)}function N(a){var c=x(a),d=null,e=null;c===n&&b.results?(b.currentIndex>=0&&b.currentIndex=1?(b.$apply(function(){b.currentIndex--,M()}),ka&&(e=K(),0>e&&L(e-1))):0===b.currentIndex&&b.$apply(function(){b.currentIndex=-1,da.val(b.searchStr)})):c===o&&(b.results&&b.results.length>0&&b.showDropdown?-1===b.currentIndex&&b.overrideSuggestions?G():(-1===b.currentIndex&&(b.currentIndex=0),b.selectResult(b.results[b.currentIndex]),b.$digest()):b.searchStr&&b.searchStr.length>0&&G())}function O(a){return function(c,d,e,f){d||e||f||(c=c.data),b.searching=!1,Y(C(_(c),b.remoteUrlDataField),a)}}function P(a,c,d,e){c||d||e||(c=a.status),0!==c&&(b.remoteUrlErrorCallback?b.remoteUrlErrorCallback(a,c,d,e):console&&console.error&&console.error("http error"))}function Q(){ia&&ia.resolve()}function R(d){var e={},f=b.remoteUrl+encodeURIComponent(d);b.remoteUrlRequestFormatter&&(e={params:b.remoteUrlRequestFormatter(d)},f=b.remoteUrl),b.remoteUrlRequestWithCredentials&&(e.withCredentials=!0),Q(),ia=a.defer(),e.timeout=ia.promise,c.get(f,e).success(O(d)).error(P)}function S(c){Q(),ia=a.defer(),b.remoteApiHandler(c,ia.promise).then(O(c))["catch"](P)}function T(){b.showDropdown=!1,b.results=[],ja&&(ja.scrollTop=0)}function U(){b.showDropdown=ba,b.currentIndex=-1,b.results=[]}function V(a){var c,d,e,f,g=b.searchFields.split(","),h=[];for(c=0;c=0;d&&(h[h.length]=b.localData[c])}b.searching=!1,Y(h,a)}function W(a,c,d){if(d)for(var e in c)if(c[e].toLowerCase()===d.toLowerCase())return void b.selectResult(a)}function X(a){!a||a.length0)for(b.results=[],d=0;d0?b.searchStr=a:console&&console.error&&console.error("Tried to set initial value of angucomplete to",a,"which is an invalid value"),E(!0))}),b.$on("angucomplete-alt:clearInput",function(a,c){c&&c!==b.id||(b.searchStr=null,y(),E(!1),T())}),b.onFocusHandler=function(){b.focusIn&&b.focusIn(),0!==ea||b.searchStr&&0!==b.searchStr.length||(b.showDropdown=!0,Z())},b.hideResults=function(a){la&&(la===b.id+"_dropdown"||la.indexOf("angucomplete")>=0)?la=null:($=e(function(){T(),b.$apply(function(){b.searchStr&&b.searchStr.length>0&&da.val(b.searchStr)})},s),Q(),b.focusOut&&b.focusOut(),b.overrideSuggestions&&b.searchStr&&b.searchStr.length>0&&-1===b.currentIndex&&G())},b.resetHideResults=function(){$&&e.cancel($)},b.hoverRow=function(a){b.currentIndex=a},b.selectResult=function(a){b.matchClass&&(a.title=B(a.originalObject),a.description=C(a.originalObject,b.descriptionField)),b.clearSelected?b.searchStr=null:b.searchStr=a.title,y(a),T()},b.inputChangeHandler=function(a){return a.length
{{ result.title }}
{{result.description}}
'),{restrict:"EA",require:"^?form",scope:{selectedObject:"=",disableInput:"=",initialValue:"=",localData:"=",remoteUrlRequestFormatter:"=",remoteUrlRequestWithCredentials:"@",remoteUrlResponseFormatter:"=",remoteUrlErrorCallback:"=",remoteApiHandler:"=",id:"@",type:"@",placeholder:"@",remoteUrl:"@",remoteUrlDataField:"@",titleField:"@",descriptionField:"@",imageField:"@",inputClass:"@",pause:"@",searchFields:"@",minlength:"@",matchClass:"@",clearSelected:"@",overrideSuggestions:"@",fieldRequired:"@",fieldRequiredClass:"@",inputChanged:"=",autoMatch:"@",focusOut:"&",focusIn:"&",inputName:"@"},templateUrl:function(a,b){return b.templateUrl||w},compile:function(a,b){var c=g.startSymbol(),d=g.endSymbol();if("{{"!==c||"}}"!==d){var e=a.html().replace(/\{\{/g,c).replace(/\}\}/g,d);a.html(e)}return h}}}])}); \ No newline at end of file +"use strict";!function(a,b){"undefined"!=typeof module&&module.exports?module.exports=b(require("angular")):"function"==typeof define&&define.amd?define(["angular"],b):b(a.angular)}(window,function(a){a.module("angucomplete-alt",[]).directive("angucompleteAlt",["$q","$parse","$http","$sce","$timeout","$templateCache","$interpolate",function(a,b,c,d,e,f,g){function h(b,f,g,h){function w(a){la=null,b.hideResults(a),document.body.removeEventListener("click",w)}function x(a){return a.which?a.which:a.keyCode}function y(a){"function"==typeof b.selectedObject?b.selectedObject(a):b.selectedObject=a,E(a?!0:!1)}function z(a){return function(c){return b[a]?b[a](c):c}}function A(a){y({originalObject:a}),b.clearSelected&&(b.searchStr=null),T()}function B(a){return b.titleField.split(",").map(function(b){return C(a,b)}).join(" ")}function C(a,b){var c,d;if(b){c=b.split("."),d=a;for(var e=0;e'+f[0]+""):a,d.trustAsHtml(e)):void 0}function E(a){b.notEmpty=a,ha=b.searchStr,b.fieldRequired&&h&&h.$setValidity(ga,a)}function F(a){var c=x(a);if(c!==l&&c!==j)if(c===k||c===n)a.preventDefault();else if(c===i)a.preventDefault(),!b.showDropdown&&b.searchStr&&b.searchStr.length>=ea&&(U(),b.searching=!0,X(b.searchStr));else if(c===m)T(),b.$apply(function(){da.val(b.searchStr)});else{if(0===ea&&!b.searchStr)return;b.searchStr&&""!==b.searchStr?b.searchStr.length>=ea&&(U(),fa&&e.cancel(fa),b.searching=!0,fa=e(function(){X(b.searchStr)},b.pause)):b.showDropdown=!1,ha&&ha!==b.searchStr&&!b.clearSelected&&b.$apply(function(){y()})}}function G(a){!b.overrideSuggestions||b.selectedObject&&b.selectedObject.originalObject===b.searchStr||(a&&a.preventDefault(),A(b.searchStr))}function H(a){var b=getComputedStyle(a);return a.offsetHeight+parseInt(b.marginTop,10)+parseInt(b.marginBottom,10)}function I(){return ja.getBoundingClientRect().top+parseInt(getComputedStyle(ja).maxHeight,10)}function J(){return f[0].querySelectorAll(".angucomplete-row")[b.currentIndex]}function K(){return J().getBoundingClientRect().top-(ja.getBoundingClientRect().top+parseInt(getComputedStyle(ja).paddingTop,10))}function L(a){ja.scrollTop=ja.scrollTop+a}function M(){var a=b.results[b.currentIndex];b.matchClass?da.val(B(a.originalObject)):da.val(a.title)}function N(a){var c=x(a),d=null,e=null;c===n&&b.results?b.currentIndex>=0&&b.currentIndex=1?(b.$apply(function(){b.currentIndex--,M()}),ka&&(e=K(),0>e&&L(e-1))):0===b.currentIndex&&b.$apply(function(){b.currentIndex=-1,da.val(b.searchStr)})):c===o&&(b.results&&b.results.length>0&&b.showDropdown?-1===b.currentIndex&&b.overrideSuggestions?G():(-1===b.currentIndex&&(b.currentIndex=0),b.selectResult(b.results[b.currentIndex]),b.$digest()):b.searchStr&&b.searchStr.length>0&&G())}function O(a){return function(c,d,e,f){d||e||f||(c=c.data),b.searching=!1,Y(C(_(c),b.remoteUrlDataField),a)}}function P(a,c,d,e){c||d||e||(c=a.status),0!==c&&(b.remoteUrlErrorCallback?b.remoteUrlErrorCallback(a,c,d,e):console&&console.error&&console.error("http error"))}function Q(){ia&&ia.resolve()}function R(d){var e={},f=b.remoteUrl+encodeURIComponent(d);b.remoteUrlRequestFormatter&&(e={params:b.remoteUrlRequestFormatter(d)},f=b.remoteUrl),b.remoteUrlRequestWithCredentials&&(e.withCredentials=!0),Q(),ia=a.defer(),e.timeout=ia.promise,c.get(f,e).success(O(d)).error(P)}function S(c){Q(),ia=a.defer(),b.remoteApiHandler(c,ia.promise).then(O(c))["catch"](P)}function T(){b.showDropdown=!1,b.results=[],ja&&(ja.scrollTop=0)}function U(){b.showDropdown=ba,b.currentIndex=-1,b.results=[]}function V(a){var c,d,e,f,g=b.searchFields.split(","),h=[];for(c=0;c=0;d&&(h[h.length]=b.localData[c])}b.searching=!1,Y(h,a)}function W(a,c,d){if(d)for(var e in c)if(c[e].toLowerCase()===d.toLowerCase())return void b.selectResult(a)}function X(a){!a||a.length0)for(b.results=[],d=0;d0?b.searchStr=a:console&&console.error&&console.error("Tried to set initial value of angucomplete to",a,"which is an invalid value"),E(!0))}),b.$on("angucomplete-alt:clearInput",function(a,c){c&&c!==b.id||(b.searchStr=null,y(),E(!1),T())}),b.onFocusHandler=function(){b.focusIn&&b.focusIn(),0!==ea||b.searchStr&&0!==b.searchStr.length||(b.showDropdown=!0,Z())},b.hideResults=function(a){la&&(la===b.id+"_dropdown"||la.indexOf("angucomplete")>=0)?la=null:($=e(function(){T(),b.$apply(function(){b.searchStr&&b.searchStr.length>0&&da.val(b.searchStr)})},s),Q(),b.focusOut&&b.focusOut(),b.overrideSuggestions&&b.searchStr&&b.searchStr.length>0&&-1===b.currentIndex&&G())},b.resetHideResults=function(){$&&e.cancel($)},b.hoverRow=function(a){b.currentIndex=a},b.selectResult=function(a){b.matchClass&&(a.title=B(a.originalObject),a.description=C(a.originalObject,b.descriptionField)),b.clearSelected?b.searchStr=null:b.searchStr=a.title,y(a),T()},b.inputChangeHandler=function(a){return a.length
{{ result.title }}
{{result.description}}
'),{restrict:"EA",require:"^?form",scope:{selectedObject:"=",disableInput:"=",initialValue:"=",localData:"=",remoteUrlRequestFormatter:"=",remoteUrlRequestWithCredentials:"@",remoteUrlResponseFormatter:"=",remoteUrlErrorCallback:"=",remoteApiHandler:"=",id:"@",type:"@",placeholder:"@",remoteUrl:"@",remoteUrlDataField:"@",titleField:"@",descriptionField:"@",imageField:"@",inputClass:"@",pause:"@",searchFields:"@",minlength:"@",matchClass:"@",clearSelected:"@",overrideSuggestions:"@",fieldRequired:"@",fieldRequiredClass:"@",inputChanged:"=",autoMatch:"@",focusOut:"&",focusIn:"&",inputName:"@"},templateUrl:function(a,b){return b.templateUrl||w},compile:function(a,b){var c=g.startSymbol(),d=g.endSymbol();if("{{"!==c||"}}"!==d){var e=a.html().replace(/\{\{/g,c).replace(/\}\}/g,d);a.html(e)}return h}}}])}); \ No newline at end of file