diff --git a/CHANGELOG.md b/CHANGELOG.md index 85ce8ab..c9eedaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## 0.2.12 +#### Features + +- **oi-select-options:** + - cleanModel: changed behavior (clean model by click) + #### Bug Fixes - **oi-select-options:** diff --git a/dist/select-tpls.js b/dist/select-tpls.js index d387f48..16ec0dd 100644 --- a/dist/select-tpls.js +++ b/dist/select-tpls.js @@ -376,11 +376,11 @@ angular.module('oi.select') placeholderFn = $interpolate(attrs.placeholder || ''), optionsFn = $parse(attrs.oiSelectOptions), keyUpDownWerePressed = false, - matchesWereReset = false, - cleanModel = true; + matchesWereReset = false; var timeoutPromise, - lastQuery; + lastQuery, + removedItem; return function(scope, element, attrs, ctrl) { var inputElement = element.find('input'), @@ -414,6 +414,10 @@ angular.module('oi.select') }; } + if (options.cleanModel) { + element.addClass('cleanMode'); + } + var unbindFocusBlur = oiUtils.bindFocusBlur(element, inputElement); if (angular.isDefined(attrs.autofocus)) { @@ -553,15 +557,12 @@ angular.module('oi.select') resetMatches({query: true}); } - cleanModel = false; scope.oldQuery = scope.oldQuery || scope.query; scope.query = ''; scope.backspaceFocus = false; }; scope.removeItem = function removeItem(position) { - var removedItem; - if (attrs.disabled || !multiple && !scope.inputHide) return; if (multiple && position >= 0) { @@ -573,6 +574,10 @@ angular.module('oi.select') if (!multiple) { removedItem = ctrl.$modelValue; cleanInput(); + + if (options.cleanModel) { + ctrl.$setViewValue(undefined); + } } if (!editItemCorrect && (multiple || !scope.backspaceFocus)) { @@ -639,6 +644,10 @@ angular.module('oi.select') case 27: /* esc */ if (!multiple) { restoreInput(); + + if (options.cleanModel) { + ctrl.$setViewValue(removedItem); + } } resetMatches(); break; @@ -665,16 +674,16 @@ angular.module('oi.select') } }; - scope.getSearchLabel = function(option) { - var label = getLabel(option); + scope.getSearchLabel = function(item) { + var label = getLabel(item); - return searchFilter(label, scope.oldQuery || scope.query, option, searchFilterOptionsFn(scope.$parent)); + return searchFilter(label, scope.oldQuery || scope.query, item, searchFilterOptionsFn(scope.$parent)); }; - scope.getDropdownLabel = function(option) { - var label = getLabel(option); + scope.getDropdownLabel = function(item) { + var label = getLabel(item); - return dropdownFilter(label, scope.oldQuery || scope.query, option, dropdownFilterOptionsFn(scope.$parent)); + return dropdownFilter(label, scope.oldQuery || scope.query, item, dropdownFilterOptionsFn(scope.$parent)); }; scope.getDisableWhen = getDisableWhen; @@ -738,14 +747,9 @@ angular.module('oi.select') scope.isFocused = false; if (!multiple) { - if (options.cleanModel && !scope.inputHide) { - ctrl.$setViewValue(undefined); - } restoreInput(); } - cleanModel = true; - saveOn('blur'); scope.$evalAsync(); } @@ -767,7 +771,6 @@ angular.module('oi.select') .then(function(data) { if (isItemSave) { scope.addItem(data); - cleanModel = true; } }) .finally(function() { diff --git a/dist/select-tpls.min.js b/dist/select-tpls.min.js index 540769f..98050e0 100644 --- a/dist/select-tpls.min.js +++ b/dist/select-tpls.min.js @@ -1 +1 @@ -angular.module("oi.select",[]),angular.module("oi.select").provider("oiSelect",function(){return{options:{debounce:500,searchFilter:"oiSelectCloseIcon",dropdownFilter:"oiSelectHighlight",listFilter:"oiSelectAscSort",editItem:!1,newItem:!1,closeList:!0,saveTrigger:"enter"},version:{full:"0.2.12",major:0,minor:2,dot:12},$get:function(){return{options:this.options,version:this.version}}}}).factory("oiSelectEditItem",function(){return function(e,t,n){return n(e)}}).factory("oiUtils",["$document","$timeout",function(e,t){function n(e,t,n){for(var o=t;o&&o.ownerDocument&&11!==o.nodeType;){if(n){if(o===e)return!1;if(o.classList.contains(n))return!0}else if(o===e)return!0;o=o.parentNode}return!1}function o(o,r){function i(){return d=!1,c?void(d=!0):void t(function(){o.triggerHandler("blur")})}function s(){a||(a=!0,t(function(){o.triggerHandler("focus")}))}function l(){c=!0}function u(e){c=!1;var s=e.target,l=n(o[0],s);d&&!l&&i(),l&&"INPUT"!==s.nodeName&&t(function(){r[0].focus()}),!l&&a&&(a=!1)}var a,c,d;return e[0].addEventListener("click",u,!0),o[0].addEventListener("mousedown",l,!0),o[0].addEventListener("blur",i,!0),r.on("focus",s),function(){e[0].removeEventListener("click",u),o[0].removeEventListener("blur",i,!0),r.off("focus",s)}}function r(e,t){var n,o,r,i,l,a;t&&(o=e.offsetHeight,r=u(t,"height","margin"),i=e.scrollTop||0,n=s(t).top-s(e).top+i,l=n,a=n-o+r,n+r>o+i?e.scrollTop=a:i>n&&(e.scrollTop=l))}function i(e,t,n,o,r){function i(e){return parseFloat(r[e])}for(var s=n===(o?"border":"content")?4:"width"===t?1:0,l=0,u=["Top","Right","Bottom","Left"];4>s;s+=2)"margin"===n&&(l+=i(n+u[s])),o?("content"===n&&(l-=i("padding"+u[s])),"margin"!==n&&(l-=i("border"+u[s]+"Width"))):(l+=i("padding"+u[s]),"padding"!==n&&(l+=i("border"+u[s]+"Width")));return l}function s(e){var t,n,o=e.getBoundingClientRect(),r=e&&e.ownerDocument;if(r)return t=r.documentElement,n=l(r),{top:o.top+n.pageYOffset-t.clientTop,left:o.left+n.pageXOffset-t.clientLeft}}function l(e){return null!=e&&e===e.window?e:9===e.nodeType&&e.defaultView}function u(e,t,n){var o=!0,r="width"===t?e.offsetWidth:e.offsetHeight,s=window.getComputedStyle(e,null),l=!1;if(0>=r||null==r){if(r=s[t],(0>r||null==r)&&(r=e.style[t]),g.test(r))return r;r=parseFloat(r)||0}return r+i(e,t,n||(l?"border":"content"),o,s)}function a(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t].length)return!1;return!0}function c(e){var t=[];return angular.forEach(e,function(e,n){"$"!==n.toString().charAt(0)&&t.push(e)}),t}function d(e,t,n,o,r){var i,s,l,u,a,c=r?[].concat(e):[];for(i=0,l=e.length;i=A&&u.contains(r[0],t.target,"select-dropdown")||(e.inputHide&&e.removeItem(0),!e.isOpen||!et.closeList||"INPUT"===t.target.nodeName&&e.query.length?M(e.query):(B({query:et.editItem&&!nt}),e.$evalAsync()))}function $(){e.isFocused||(e.isFocused=!0,c.disabled||(e.backspaceFocus=!1))}function w(){e.isFocused=!1,O||(et.cleanModel&&!e.inputHide&&d.$setViewValue(void 0),g()),Q=!0,y("blur"),e.$evalAsync()}function y(o){var r=new RegExp(o).test(et.saveTrigger),i=et.newItem&&e.query,s=angular.isNumber(e.selectorPosition),l=e.order[e.selectorPosition],u=t.reject(),a="blur"!==o||e.query||!et.newItem;r&&(i||s&&l)&&(e.showLoader=!0,u=t.when("blur"!==o&&l||e.query&&Y(e.$parent,{$query:e.query}))),u.then(function(t){a&&(e.addItem(t),Q=!0)}).finally(function(){var t=e.order.length-1;e.selectorPosition===t&&z(J,0),et.newItemFn&&!s||n(angular.noop),B()})}function I(){var e=O&&d.$modelValue&&d.$modelValue.length?"":K;G.attr("placeholder",e)}function k(t){return u.getValue(b,t,e.$parent,C)}function q(t){return u.getValue(b,t,e.$parent,V)}function F(t){return String(u.getValue(b,t,e.$parent,P))}function R(t){return u.getValue(b,t,e.$parent,L)}function U(t){return u.getValue(b,t,e.$parent,E)||""}function j(t){return u.getValue(S,t,e.$parent,x)}function M(o,r){var i=H(e.$parent,{$query:o,$selectedAs:r}),s=0;return e.selectorPosition="prompt"===et.newItem?!1:0,o||r||(e.oldQuery=null),m&&(i.$promise&&!i.$resolved||angular.isFunction(i.then))&&(n.cancel(m),s=et.debounce),m=n(function(){return e.showLoader=!0,t.when(i.$promise||i).then(function(t){if(!r){var n=O?e.output:[],i=ut(u.objToArr(t),o,F,at(e.$parent)),s=u.intersection(i,n,k,k,!0),l=j(s);e.groups=X(l),W()}return t}).finally(function(){e.showLoader=!1})},s)}function W(){var t,n,o,r=[],i=0;e.order=[],e.groupPos={};for(n in e.groups)e.groups.hasOwnProperty(n)&&"$"!=n.charAt(0)&&r.push(n);for(angular.version.major<=1&&angular.version.minor<=3&&r.sort(),t=0;t=A)return r.addClass("limited"),void n(function(){r.removeClass("limited")},150);var o=e.groups[U(t)]=e.groups[U(t)]||[],i=V?q(t):t;o.splice(o.indexOf(t),1),O?d.$setViewValue(angular.isArray(d.$modelValue)?d.$modelValue.concat(i):[i]):(d.$setViewValue(i),g()),u.groupsIsEmpty(e.groups)&&(e.groups={}),O||et.closeList||B({query:!0}),Q=!1,e.oldQuery=e.oldQuery||e.query,e.query="",e.backspaceFocus=!1}},e.removeItem=function(t){var n;c.disabled||!O&&!e.inputHide||(O&&t>=0&&(n=d.$modelValue[t],d.$modelValue.splice(t,1),d.$setViewValue([].concat(d.$modelValue))),O||(n=d.$modelValue,p()),nt||!O&&e.backspaceFocus||(e.query=ot(n,h,F)),nt=!1,O&&et.closeList&&B({query:!0}))},e.setSelection=function(t){T||e.selectorPosition===t?T=!1:z(J,t)},e.keyUp=function(t){switch(t.keyCode){case 8:e.query.length||O&&e.output.length||B()}},e.keyDown=function(t){var n=0,o=e.order.length-1;switch(t.keyCode){case 38:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n,z(J,e.selectorPosition===n?o:e.selectorPosition-1),T=!0;break;case 40:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n-1,z(J,e.selectorPosition===o?n:e.selectorPosition+1),T=!0,e.query.length||e.isOpen||M(),e.inputHide&&p();break;case 37:case 39:break;case 13:y("enter"),t.preventDefault();break;case 27:O||g(),B();break;case 8:if(!e.query.length){if((!O||tt)&&(e.backspaceFocus=!0),e.backspaceFocus&&e.output){e.removeItem(e.output.length-1),tt&&t.preventDefault();break}e.backspaceFocus=!e.backspaceFocus;break}default:return e.backspaceFocus=!1,!1}},e.getSearchLabel=function(t){var n=F(t);return rt(n,e.oldQuery||e.query,t,it(e.$parent))},e.getDropdownLabel=function(t){var n=F(t);return st(n,e.oldQuery||e.query,t,lt(e.$parent))},e.getDisableWhen=R,O&&(d.$isEmpty=function(e){return!e||!e.length}),B(),r[0].addEventListener("click",v,!0),r.on("focus",$),r.on("blur",w)}}}}]),angular.module("oi.select").filter("oiSelectCloseIcon",["$sce",function(e){return function(t){var n='×';return e.trustAsHtml(t+n)}}]).filter("oiSelectHighlight",["$sce",function(e){return function(t,n){var o;return n.length>0||angular.isNumber(n)?(t=t.toString(),n=n.toString().replace(/\s+.*/,"").replace(/\\/g,"\\\\"),o=t.replace(new RegExp(n,"gi"),"$&")):o=t,e.trustAsHtml(o)}}]).filter("oiSelectAscSort",function(){function e(e,t,n,o){var r,i,s,l,u=[],a=[],c=[];if(t){for(t=String(t).replace(/\s+.*/,"").replace(/\\/g,"\\\\"),r=0,s=!1;r
')}]); \ No newline at end of file +angular.module("oi.select",[]),angular.module("oi.select").provider("oiSelect",function(){return{options:{debounce:500,searchFilter:"oiSelectCloseIcon",dropdownFilter:"oiSelectHighlight",listFilter:"oiSelectAscSort",editItem:!1,newItem:!1,closeList:!0,saveTrigger:"enter"},version:{full:"0.2.12",major:0,minor:2,dot:12},$get:function(){return{options:this.options,version:this.version}}}}).factory("oiSelectEditItem",function(){return function(e,t,n){return n(e)}}).factory("oiUtils",["$document","$timeout",function(e,t){function n(e,t,n){for(var o=t;o&&o.ownerDocument&&11!==o.nodeType;){if(n){if(o===e)return!1;if(o.classList.contains(n))return!0}else if(o===e)return!0;o=o.parentNode}return!1}function o(o,r){function i(){return d=!1,c?void(d=!0):void t(function(){o.triggerHandler("blur")})}function s(){a||(a=!0,t(function(){o.triggerHandler("focus")}))}function l(){c=!0}function u(e){c=!1;var s=e.target,l=n(o[0],s);d&&!l&&i(),l&&"INPUT"!==s.nodeName&&t(function(){r[0].focus()}),!l&&a&&(a=!1)}var a,c,d;return e[0].addEventListener("click",u,!0),o[0].addEventListener("mousedown",l,!0),o[0].addEventListener("blur",i,!0),r.on("focus",s),function(){e[0].removeEventListener("click",u),o[0].removeEventListener("mousedown",l,!0),o[0].removeEventListener("blur",i,!0),r.off("focus",s)}}function r(e,t){var n,o,r,i,l,a;t&&(o=e.offsetHeight,r=u(t,"height","margin"),i=e.scrollTop||0,n=s(t).top-s(e).top+i,l=n,a=n-o+r,n+r>o+i?e.scrollTop=a:i>n&&(e.scrollTop=l))}function i(e,t,n,o,r){function i(e){return parseFloat(r[e])}for(var s=n===(o?"border":"content")?4:"width"===t?1:0,l=0,u=["Top","Right","Bottom","Left"];4>s;s+=2)"margin"===n&&(l+=i(n+u[s])),o?("content"===n&&(l-=i("padding"+u[s])),"margin"!==n&&(l-=i("border"+u[s]+"Width"))):(l+=i("padding"+u[s]),"padding"!==n&&(l+=i("border"+u[s]+"Width")));return l}function s(e){var t,n,o=e.getBoundingClientRect(),r=e&&e.ownerDocument;if(r)return t=r.documentElement,n=l(r),{top:o.top+n.pageYOffset-t.clientTop,left:o.left+n.pageXOffset-t.clientLeft}}function l(e){return null!=e&&e===e.window?e:9===e.nodeType&&e.defaultView}function u(e,t,n){var o=!0,r="width"===t?e.offsetWidth:e.offsetHeight,s=window.getComputedStyle(e,null),l=!1;if(0>=r||null==r){if(r=s[t],(0>r||null==r)&&(r=e.style[t]),g.test(r))return r;r=parseFloat(r)||0}return r+i(e,t,n||(l?"border":"content"),o,s)}function a(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t].length)return!1;return!0}function c(e){var t=[];return angular.forEach(e,function(e,n){"$"!==n.toString().charAt(0)&&t.push(e)}),t}function d(e,t,n,o,r){var i,s,l,u,a,c=r?[].concat(e):[];for(i=0,l=e.length;i=D&&u.contains(r[0],t.target,"select-dropdown")||(e.inputHide&&e.removeItem(0),!e.isOpen||!et.closeList||"INPUT"===t.target.nodeName&&e.query.length?j(e.query):(B({query:et.editItem&&!nt}),e.$evalAsync()))}function w(){e.isFocused||(e.isFocused=!0,c.disabled||(e.backspaceFocus=!1))}function y(){e.isFocused=!1,A||g(),I("blur"),e.$evalAsync()}function I(o){var r=new RegExp(o).test(et.saveTrigger),i=et.newItem&&e.query,s=angular.isNumber(e.selectorPosition),l=e.order[e.selectorPosition],u=t.reject(),a="blur"!==o||e.query||!et.newItem;r&&(i||s&&l)&&(e.showLoader=!0,u=t.when("blur"!==o&&l||e.query&&Y(e.$parent,{$query:e.query}))),u.then(function(t){a&&e.addItem(t)}).finally(function(){var t=e.order.length-1;e.selectorPosition===t&&z(J,0),et.newItemFn&&!s||n(angular.noop),B()})}function k(){var e=A&&d.$modelValue&&d.$modelValue.length?"":K;G.attr("placeholder",e)}function S(t){return u.getValue(b,t,e.$parent,O)}function q(t){return u.getValue(b,t,e.$parent,E)}function F(t){return String(u.getValue(b,t,e.$parent,L))}function Q(t){return u.getValue(b,t,e.$parent,x)}function R(t){return u.getValue(b,t,e.$parent,P)||""}function U(t){return u.getValue(V,t,e.$parent,C)}function j(o,r){var i=H(e.$parent,{$query:o,$selectedAs:r}),s=0;return e.selectorPosition="prompt"===et.newItem?!1:0,o||r||(e.oldQuery=null),m&&(i.$promise&&!i.$resolved||angular.isFunction(i.then))&&(n.cancel(m),s=et.debounce),m=n(function(){return e.showLoader=!0,t.when(i.$promise||i).then(function(t){if(!r){var n=A?e.output:[],i=ut(u.objToArr(t),o,F,at(e.$parent)),s=u.intersection(i,n,S,S,!0),l=U(s);e.groups=X(l),W()}return t}).finally(function(){e.showLoader=!1})},s)}function W(){var t,n,o,r=[],i=0;e.order=[],e.groupPos={};for(n in e.groups)e.groups.hasOwnProperty(n)&&"$"!=n.charAt(0)&&r.push(n);for(angular.version.major<=1&&angular.version.minor<=3&&r.sort(),t=0;t=D)return r.addClass("limited"),void n(function(){r.removeClass("limited")},150);var o=e.groups[R(t)]=e.groups[R(t)]||[],i=E?q(t):t;o.splice(o.indexOf(t),1),A?d.$setViewValue(angular.isArray(d.$modelValue)?d.$modelValue.concat(i):[i]):(d.$setViewValue(i),g()),u.groupsIsEmpty(e.groups)&&(e.groups={}),A||et.closeList||B({query:!0}),e.oldQuery=e.oldQuery||e.query,e.query="",e.backspaceFocus=!1}},e.removeItem=function(t){c.disabled||!A&&!e.inputHide||(A&&t>=0&&(v=d.$modelValue[t],d.$modelValue.splice(t,1),d.$setViewValue([].concat(d.$modelValue))),A||(v=d.$modelValue,p(),et.cleanModel&&d.$setViewValue(void 0)),nt||!A&&e.backspaceFocus||(e.query=ot(v,h,F)),nt=!1,A&&et.closeList&&B({query:!0}))},e.setSelection=function(t){N||e.selectorPosition===t?N=!1:z(J,t)},e.keyUp=function(t){switch(t.keyCode){case 8:e.query.length||A&&e.output.length||B()}},e.keyDown=function(t){var n=0,o=e.order.length-1;switch(t.keyCode){case 38:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n,z(J,e.selectorPosition===n?o:e.selectorPosition-1),N=!0;break;case 40:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n-1,z(J,e.selectorPosition===o?n:e.selectorPosition+1),N=!0,e.query.length||e.isOpen||j(),e.inputHide&&p();break;case 37:case 39:break;case 13:I("enter"),t.preventDefault();break;case 27:A||(g(),et.cleanModel&&d.$setViewValue(v)),B();break;case 8:if(!e.query.length){if((!A||tt)&&(e.backspaceFocus=!0),e.backspaceFocus&&e.output){e.removeItem(e.output.length-1),tt&&t.preventDefault();break}e.backspaceFocus=!e.backspaceFocus;break}default:return e.backspaceFocus=!1,!1}},e.getSearchLabel=function(t){var n=F(t);return rt(n,e.oldQuery||e.query,t,it(e.$parent))},e.getDropdownLabel=function(t){var n=F(t);return st(n,e.oldQuery||e.query,t,lt(e.$parent))},e.getDisableWhen=Q,A&&(d.$isEmpty=function(e){return!e||!e.length}),B(),r[0].addEventListener("click",$,!0),r.on("focus",w),r.on("blur",y)}}}}]),angular.module("oi.select").filter("oiSelectCloseIcon",["$sce",function(e){return function(t){var n='×';return e.trustAsHtml(t+n)}}]).filter("oiSelectHighlight",["$sce",function(e){return function(t,n){var o;return n.length>0||angular.isNumber(n)?(t=t.toString(),n=n.toString().replace(/\s+.*/,"").replace(/\\/g,"\\\\"),o=t.replace(new RegExp(n,"gi"),"$&")):o=t,e.trustAsHtml(o)}}]).filter("oiSelectAscSort",function(){function e(e,t,n,o){var r,i,s,l,u=[],a=[],c=[];if(t){for(t=String(t).replace(/\s+.*/,"").replace(/\\/g,"\\\\"),r=0,s=!1;r
')}]); \ No newline at end of file diff --git a/dist/select.css b/dist/select.css index 170b4be..6e43278 100644 --- a/dist/select.css +++ b/dist/select.css @@ -126,13 +126,13 @@ oi-select:not([multiple]) .select-search-list-item_selection { border-color: #fff; text-align: left; } -oi-select:not([multiple]) .select-search-list-item_selection-remove { - display: none; -} oi-select:not([multiple]) .select-search-list-item_selection:not(:active) { background: none; } -oi-select:not([multiple]) .select-search:after { +oi-select:not([multiple]):not(.cleanMode) .select-search-list-item_selection-remove { + display: none; +} +oi-select:not([multiple]):not(.cleanMode) .select-search:after { content: ""; position: absolute; display: block; diff --git a/dist/select.js b/dist/select.js index 23978d9..f9b993b 100644 --- a/dist/select.js +++ b/dist/select.js @@ -376,11 +376,11 @@ angular.module('oi.select') placeholderFn = $interpolate(attrs.placeholder || ''), optionsFn = $parse(attrs.oiSelectOptions), keyUpDownWerePressed = false, - matchesWereReset = false, - cleanModel = true; + matchesWereReset = false; var timeoutPromise, - lastQuery; + lastQuery, + removedItem; return function(scope, element, attrs, ctrl) { var inputElement = element.find('input'), @@ -414,6 +414,10 @@ angular.module('oi.select') }; } + if (options.cleanModel) { + element.addClass('cleanMode'); + } + var unbindFocusBlur = oiUtils.bindFocusBlur(element, inputElement); if (angular.isDefined(attrs.autofocus)) { @@ -553,15 +557,12 @@ angular.module('oi.select') resetMatches({query: true}); } - cleanModel = false; scope.oldQuery = scope.oldQuery || scope.query; scope.query = ''; scope.backspaceFocus = false; }; scope.removeItem = function removeItem(position) { - var removedItem; - if (attrs.disabled || !multiple && !scope.inputHide) return; if (multiple && position >= 0) { @@ -573,6 +574,10 @@ angular.module('oi.select') if (!multiple) { removedItem = ctrl.$modelValue; cleanInput(); + + if (options.cleanModel) { + ctrl.$setViewValue(undefined); + } } if (!editItemCorrect && (multiple || !scope.backspaceFocus)) { @@ -639,6 +644,10 @@ angular.module('oi.select') case 27: /* esc */ if (!multiple) { restoreInput(); + + if (options.cleanModel) { + ctrl.$setViewValue(removedItem); + } } resetMatches(); break; @@ -665,16 +674,16 @@ angular.module('oi.select') } }; - scope.getSearchLabel = function(option) { - var label = getLabel(option); + scope.getSearchLabel = function(item) { + var label = getLabel(item); - return searchFilter(label, scope.oldQuery || scope.query, option, searchFilterOptionsFn(scope.$parent)); + return searchFilter(label, scope.oldQuery || scope.query, item, searchFilterOptionsFn(scope.$parent)); }; - scope.getDropdownLabel = function(option) { - var label = getLabel(option); + scope.getDropdownLabel = function(item) { + var label = getLabel(item); - return dropdownFilter(label, scope.oldQuery || scope.query, option, dropdownFilterOptionsFn(scope.$parent)); + return dropdownFilter(label, scope.oldQuery || scope.query, item, dropdownFilterOptionsFn(scope.$parent)); }; scope.getDisableWhen = getDisableWhen; @@ -738,14 +747,9 @@ angular.module('oi.select') scope.isFocused = false; if (!multiple) { - if (options.cleanModel && !scope.inputHide) { - ctrl.$setViewValue(undefined); - } restoreInput(); } - cleanModel = true; - saveOn('blur'); scope.$evalAsync(); } @@ -767,7 +771,6 @@ angular.module('oi.select') .then(function(data) { if (isItemSave) { scope.addItem(data); - cleanModel = true; } }) .finally(function() { diff --git a/dist/select.min.css b/dist/select.min.css index 84dbb3a..2c52ba5 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1 +1 @@ -oi-select{display:block;position:relative;width:100%}oi-select .select-search{cursor:text;border:1px solid #d9d9d9;background-color:#fff;overflow:hidden!important;-moz-box-sizing:border-box;box-sizing:border-box;border-radius:4px}oi-select .select-search-list{display:-webkit-box;display:-webkit-flex;display:-moz-box;display:-ms-flexbox;display:flex;-webkit-flex-flow:row wrap;-ms-flex-flow:row wrap;flex-flow:row wrap;-webkit-box-pack:start;-webkit-justify-content:flex-start;-moz-box-pack:start;-ms-flex-pack:start;justify-content:flex-start;margin:0;padding:2px 4px;list-style:none}oi-select .select-search-list-item{font-size:14px;margin:2px 4px 2px 0;vertical-align:middle;white-space:normal}oi-select .select-search-list-item_selection{cursor:pointer;background:#efefef;border-color:#ebebeb}oi-select .select-search-list-item_selection:hover{border-color:#e5e5e5}oi-select .select-search-list-item_selection.focused,oi-select .select-search-list-item_selection:active{border:1px solid #fff;border-radius:0;box-shadow:inset 0 0 10px 5px #fff}oi-select .select-search-list-item_selection.focused .close{display:none}oi-select .select-search-list-item_selection-remove{padding-left:2px}oi-select .select-search-list-item_loader{float:right;margin-top:6px;width:16px;height:16px;background:url(data:image/gif;base64,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) top}oi-select .select-search-list-item_input{-webkit-box-flex:1;-webkit-flex-grow:1;-moz-box-flex:1;-ms-flex-positive:1;flex-grow:1;margin:4px 0 5px 5px}oi-select .select-search-list-item_input input{padding:0;outline:0;border:0;width:100%}oi-select .select-search-list-item_hide{position:fixed;width:0;height:0;margin:0;opacity:0;pointer-events:none;text-indent:-9999em}oi-select .select-dropdown{position:absolute;width:inherit;overflow-y:scroll;max-height:100px;min-width:160px;font-size:14px;background-color:#fff;border-radius:0 0 4px 4px;border:1px solid #66afe9;border-top:0;outline:0;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);background-clip:padding-box;z-index:1000}oi-select .select-dropdown-optgroup{margin:0;padding:0}oi-select .select-dropdown-optgroup-header{font-weight:bolder;padding:3px 10px}oi-select .select-dropdown-optgroup-option{padding:3px 20px}oi-select .select-dropdown-optgroup-option.active:not(.disabled){background-color:#f1f1f1;cursor:pointer}oi-select .select-dropdown-optgroup-option.disabled{color:#aaa}oi-select:not([multiple]) .select-search-list-item_selection{color:#000;width:100%;border-color:#fff;text-align:left}oi-select:not([multiple]) .select-search-list-item_selection-remove{display:none}oi-select:not([multiple]) .select-search-list-item_selection:not(:active){background:0 0}oi-select:not([multiple]) .select-search:after{content:"";position:absolute;display:block;right:10px;width:0;height:0;margin-top:-19px;border-color:#000 transparent transparent;border-style:solid;border-width:5px 5px 0}oi-select[disabled=disabled] .select-search{cursor:not-allowed;background:#eee;border:1px solid #bdbdbd;opacity:.5}oi-select[disabled=disabled] .select-search-list-item_selection{cursor:not-allowed;box-shadow:none;border-color:transparent}oi-select[disabled=disabled] .select-search-list-item_selection-remove{visibility:hidden}oi-select[disabled=disabled] .select-search-list-item_input input:disabled{cursor:not-allowed;background:0 0}oi-select.focused .select-search{border-color:#66afe9;outline:0;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}oi-select.limited .select-dropdown,oi-select.limited .select-search{border-color:#f1bc28;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(230,189,46,.6)}oi-select.open .select-search{border-radius:4px 4px 0 0;border-bottom:1px solid rgba(0,0,0,.075)}oi-select.open:not([multiple]) .select-search:after{border-color:transparent transparent #000;border-width:0 5px 5px}oi-select.loading:not([multiple]) .select-search:after{border-width:0} \ No newline at end of file +oi-select{display:block;position:relative;width:100%}oi-select .select-search{cursor:text;border:1px solid #d9d9d9;background-color:#fff;overflow:hidden!important;-moz-box-sizing:border-box;box-sizing:border-box;border-radius:4px}oi-select .select-search-list{display:-webkit-box;display:-webkit-flex;display:-moz-box;display:-ms-flexbox;display:flex;-webkit-flex-flow:row wrap;-ms-flex-flow:row wrap;flex-flow:row wrap;-webkit-box-pack:start;-webkit-justify-content:flex-start;-moz-box-pack:start;-ms-flex-pack:start;justify-content:flex-start;margin:0;padding:2px 4px;list-style:none}oi-select .select-search-list-item{font-size:14px;margin:2px 4px 2px 0;vertical-align:middle;white-space:normal}oi-select .select-search-list-item_selection{cursor:pointer;background:#efefef;border-color:#ebebeb}oi-select .select-search-list-item_selection:hover{border-color:#e5e5e5}oi-select .select-search-list-item_selection.focused,oi-select .select-search-list-item_selection:active{border:1px solid #fff;border-radius:0;box-shadow:inset 0 0 10px 5px #fff}oi-select .select-search-list-item_selection.focused .close{display:none}oi-select .select-search-list-item_selection-remove{padding-left:2px}oi-select .select-search-list-item_loader{float:right;margin-top:6px;width:16px;height:16px;background:url(data:image/gif;base64,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) top}oi-select .select-search-list-item_input{-webkit-box-flex:1;-webkit-flex-grow:1;-moz-box-flex:1;-ms-flex-positive:1;flex-grow:1;margin:4px 0 5px 5px}oi-select .select-search-list-item_input input{padding:0;outline:0;border:0;width:100%}oi-select .select-search-list-item_hide{position:fixed;width:0;height:0;margin:0;opacity:0;pointer-events:none;text-indent:-9999em}oi-select .select-dropdown{position:absolute;width:inherit;overflow-y:scroll;max-height:100px;min-width:160px;font-size:14px;background-color:#fff;border-radius:0 0 4px 4px;border:1px solid #66afe9;border-top:0;outline:0;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);background-clip:padding-box;z-index:1000}oi-select .select-dropdown-optgroup{margin:0;padding:0}oi-select .select-dropdown-optgroup-header{font-weight:bolder;padding:3px 10px}oi-select .select-dropdown-optgroup-option{padding:3px 20px}oi-select .select-dropdown-optgroup-option.active:not(.disabled){background-color:#f1f1f1;cursor:pointer}oi-select .select-dropdown-optgroup-option.disabled{color:#aaa}oi-select:not([multiple]) .select-search-list-item_selection{color:#000;width:100%;border-color:#fff;text-align:left}oi-select:not([multiple]) .select-search-list-item_selection:not(:active){background:0 0}oi-select:not([multiple]):not(.cleanMode) .select-search-list-item_selection-remove{display:none}oi-select:not([multiple]):not(.cleanMode) .select-search:after{content:"";position:absolute;display:block;right:10px;width:0;height:0;margin-top:-19px;border-color:#000 transparent transparent;border-style:solid;border-width:5px 5px 0}oi-select[disabled=disabled] .select-search{cursor:not-allowed;background:#eee;border:1px solid #bdbdbd;opacity:.5}oi-select[disabled=disabled] .select-search-list-item_selection{cursor:not-allowed;box-shadow:none;border-color:transparent}oi-select[disabled=disabled] .select-search-list-item_selection-remove{visibility:hidden}oi-select[disabled=disabled] .select-search-list-item_input input:disabled{cursor:not-allowed;background:0 0}oi-select.focused .select-search{border-color:#66afe9;outline:0;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}oi-select.limited .select-dropdown,oi-select.limited .select-search{border-color:#f1bc28;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(230,189,46,.6)}oi-select.open .select-search{border-radius:4px 4px 0 0;border-bottom:1px solid rgba(0,0,0,.075)}oi-select.open:not([multiple]) .select-search:after{border-color:transparent transparent #000;border-width:0 5px 5px}oi-select.loading:not([multiple]) .select-search:after{border-width:0} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index e56d110..72fac9c 100644 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1 +1 @@ -angular.module("oi.select",[]),angular.module("oi.select").provider("oiSelect",function(){return{options:{debounce:500,searchFilter:"oiSelectCloseIcon",dropdownFilter:"oiSelectHighlight",listFilter:"oiSelectAscSort",editItem:!1,newItem:!1,closeList:!0,saveTrigger:"enter"},version:{full:"0.2.12",major:0,minor:2,dot:12},$get:function(){return{options:this.options,version:this.version}}}}).factory("oiSelectEditItem",function(){return function(e,t,n){return n(e)}}).factory("oiUtils",["$document","$timeout",function(e,t){function n(e,t,n){for(var r=t;r&&r.ownerDocument&&11!==r.nodeType;){if(n){if(r===e)return!1;if(r.classList.contains(n))return!0}else if(r===e)return!0;r=r.parentNode}return!1}function r(r,o){function i(){return d=!1,c?void(d=!0):void t(function(){r.triggerHandler("blur")})}function u(){a||(a=!0,t(function(){r.triggerHandler("focus")}))}function s(){c=!0}function l(e){c=!1;var u=e.target,s=n(r[0],u);d&&!s&&i(),s&&"INPUT"!==u.nodeName&&t(function(){o[0].focus()}),!s&&a&&(a=!1)}var a,c,d;return e[0].addEventListener("click",l,!0),r[0].addEventListener("mousedown",s,!0),r[0].addEventListener("blur",i,!0),o.on("focus",u),function(){e[0].removeEventListener("click",l),r[0].removeEventListener("blur",i,!0),o.off("focus",u)}}function o(e,t){var n,r,o,i,s,a;t&&(r=e.offsetHeight,o=l(t,"height","margin"),i=e.scrollTop||0,n=u(t).top-u(e).top+i,s=n,a=n-r+o,n+o>r+i?e.scrollTop=a:i>n&&(e.scrollTop=s))}function i(e,t,n,r,o){function i(e){return parseFloat(o[e])}for(var u=n===(r?"border":"content")?4:"width"===t?1:0,s=0,l=["Top","Right","Bottom","Left"];4>u;u+=2)"margin"===n&&(s+=i(n+l[u])),r?("content"===n&&(s-=i("padding"+l[u])),"margin"!==n&&(s-=i("border"+l[u]+"Width"))):(s+=i("padding"+l[u]),"padding"!==n&&(s+=i("border"+l[u]+"Width")));return s}function u(e){var t,n,r=e.getBoundingClientRect(),o=e&&e.ownerDocument;if(o)return t=o.documentElement,n=s(o),{top:r.top+n.pageYOffset-t.clientTop,left:r.left+n.pageXOffset-t.clientLeft}}function s(e){return null!=e&&e===e.window?e:9===e.nodeType&&e.defaultView}function l(e,t,n){var r=!0,o="width"===t?e.offsetWidth:e.offsetHeight,u=window.getComputedStyle(e,null),s=!1;if(0>=o||null==o){if(o=u[t],(0>o||null==o)&&(o=e.style[t]),g.test(o))return o;o=parseFloat(o)||0}return o+i(e,t,n||(s?"border":"content"),r,u)}function a(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t].length)return!1;return!0}function c(e){var t=[];return angular.forEach(e,function(e,n){"$"!==n.toString().charAt(0)&&t.push(e)}),t}function d(e,t,n,r,o){var i,u,s,l,a,c=o?[].concat(e):[];for(i=0,s=e.length;i=x&&l.contains(o[0],t.target,"select-dropdown")||(e.inputHide&&e.removeItem(0),!e.isOpen||!et.closeList||"INPUT"===t.target.nodeName&&e.query.length?M(e.query):(W({query:et.editItem&&!nt}),e.$evalAsync()))}function $(){e.isFocused||(e.isFocused=!0,c.disabled||(e.backspaceFocus=!1))}function y(){e.isFocused=!1,O||(et.cleanModel&&!e.inputHide&&d.$setViewValue(void 0),g()),Q=!0,b("blur"),e.$evalAsync()}function b(r){var o=new RegExp(r).test(et.saveTrigger),i=et.newItem&&e.query,u=angular.isNumber(e.selectorPosition),s=e.order[e.selectorPosition],l=t.reject(),a="blur"!==r||e.query||!et.newItem;o&&(i||u&&s)&&(e.showLoader=!0,l=t.when("blur"!==r&&s||e.query&&Y(e.$parent,{$query:e.query}))),l.then(function(t){a&&(e.addItem(t),Q=!0)}).finally(function(){var t=e.order.length-1;e.selectorPosition===t&&z(J,0),et.newItemFn&&!u||n(angular.noop),W()})}function I(){var e=O&&d.$modelValue&&d.$modelValue.length?"":K;G.attr("placeholder",e)}function S(t){return l.getValue(w,t,e.$parent,H)}function F(t){return l.getValue(w,t,e.$parent,V)}function k(t){return String(l.getValue(w,t,e.$parent,E))}function R(t){return l.getValue(w,t,e.$parent,L)}function j(t){return l.getValue(w,t,e.$parent,P)||""}function U(t){return l.getValue(q,t,e.$parent,A)}function M(r,o){var i=C(e.$parent,{$query:r,$selectedAs:o}),u=0;return e.selectorPosition="prompt"===et.newItem?!1:0,r||o||(e.oldQuery=null),m&&(i.$promise&&!i.$resolved||angular.isFunction(i.then))&&(n.cancel(m),u=et.debounce),m=n(function(){return e.showLoader=!0,t.when(i.$promise||i).then(function(t){if(!o){var n=O?e.output:[],i=lt(l.objToArr(t),r,k,at(e.$parent)),u=l.intersection(i,n,S,S,!0),s=U(u);e.groups=X(s),B()}return t}).finally(function(){e.showLoader=!1})},u)}function B(){var t,n,r,o=[],i=0;e.order=[],e.groupPos={};for(n in e.groups)e.groups.hasOwnProperty(n)&&"$"!=n.charAt(0)&&o.push(n);for(angular.version.major<=1&&angular.version.minor<=3&&o.sort(),t=0;t=x)return o.addClass("limited"),void n(function(){o.removeClass("limited")},150);var r=e.groups[j(t)]=e.groups[j(t)]||[],i=V?F(t):t;r.splice(r.indexOf(t),1),O?d.$setViewValue(angular.isArray(d.$modelValue)?d.$modelValue.concat(i):[i]):(d.$setViewValue(i),g()),l.groupsIsEmpty(e.groups)&&(e.groups={}),O||et.closeList||W({query:!0}),Q=!1,e.oldQuery=e.oldQuery||e.query,e.query="",e.backspaceFocus=!1}},e.removeItem=function(t){var n;c.disabled||!O&&!e.inputHide||(O&&t>=0&&(n=d.$modelValue[t],d.$modelValue.splice(t,1),d.$setViewValue([].concat(d.$modelValue))),O||(n=d.$modelValue,f()),nt||!O&&e.backspaceFocus||(e.query=rt(n,h,k)),nt=!1,O&&et.closeList&&W({query:!0}))},e.setSelection=function(t){_||e.selectorPosition===t?_=!1:z(J,t)},e.keyUp=function(t){switch(t.keyCode){case 8:e.query.length||O&&e.output.length||W()}},e.keyDown=function(t){var n=0,r=e.order.length-1;switch(t.keyCode){case 38:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n,z(J,e.selectorPosition===n?r:e.selectorPosition-1),_=!0;break;case 40:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n-1,z(J,e.selectorPosition===r?n:e.selectorPosition+1),_=!0,e.query.length||e.isOpen||M(),e.inputHide&&f();break;case 37:case 39:break;case 13:b("enter"),t.preventDefault();break;case 27:O||g(),W();break;case 8:if(!e.query.length){if((!O||tt)&&(e.backspaceFocus=!0),e.backspaceFocus&&e.output){e.removeItem(e.output.length-1),tt&&t.preventDefault();break}e.backspaceFocus=!e.backspaceFocus;break}default:return e.backspaceFocus=!1,!1}},e.getSearchLabel=function(t){var n=k(t);return ot(n,e.oldQuery||e.query,t,it(e.$parent))},e.getDropdownLabel=function(t){var n=k(t);return ut(n,e.oldQuery||e.query,t,st(e.$parent))},e.getDisableWhen=R,O&&(d.$isEmpty=function(e){return!e||!e.length}),W(),o[0].addEventListener("click",v,!0),o.on("focus",$),o.on("blur",y)}}}}]),angular.module("oi.select").filter("oiSelectCloseIcon",["$sce",function(e){return function(t){var n='×';return e.trustAsHtml(t+n)}}]).filter("oiSelectHighlight",["$sce",function(e){return function(t,n){var r;return n.length>0||angular.isNumber(n)?(t=t.toString(),n=n.toString().replace(/\s+.*/,"").replace(/\\/g,"\\\\"),r=t.replace(new RegExp(n,"gi"),"$&")):r=t,e.trustAsHtml(r)}}]).filter("oiSelectAscSort",function(){function e(e,t,n,r){var o,i,u,s,l=[],a=[],c=[];if(t){for(t=String(t).replace(/\s+.*/,"").replace(/\\/g,"\\\\"),o=0,u=!1;or+i?e.scrollTop=a:i>n&&(e.scrollTop=s))}function i(e,t,n,r,o){function i(e){return parseFloat(o[e])}for(var u=n===(r?"border":"content")?4:"width"===t?1:0,s=0,l=["Top","Right","Bottom","Left"];4>u;u+=2)"margin"===n&&(s+=i(n+l[u])),r?("content"===n&&(s-=i("padding"+l[u])),"margin"!==n&&(s-=i("border"+l[u]+"Width"))):(s+=i("padding"+l[u]),"padding"!==n&&(s+=i("border"+l[u]+"Width")));return s}function u(e){var t,n,r=e.getBoundingClientRect(),o=e&&e.ownerDocument;if(o)return t=o.documentElement,n=s(o),{top:r.top+n.pageYOffset-t.clientTop,left:r.left+n.pageXOffset-t.clientLeft}}function s(e){return null!=e&&e===e.window?e:9===e.nodeType&&e.defaultView}function l(e,t,n){var r=!0,o="width"===t?e.offsetWidth:e.offsetHeight,u=window.getComputedStyle(e,null),s=!1;if(0>=o||null==o){if(o=u[t],(0>o||null==o)&&(o=e.style[t]),g.test(o))return o;o=parseFloat(o)||0}return o+i(e,t,n||(s?"border":"content"),r,u)}function a(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t].length)return!1;return!0}function c(e){var t=[];return angular.forEach(e,function(e,n){"$"!==n.toString().charAt(0)&&t.push(e)}),t}function d(e,t,n,r,o){var i,u,s,l,a,c=o?[].concat(e):[];for(i=0,s=e.length;i=T&&l.contains(o[0],t.target,"select-dropdown")||(e.inputHide&&e.removeItem(0),!e.isOpen||!et.closeList||"INPUT"===t.target.nodeName&&e.query.length?U(e.query):(W({query:et.editItem&&!nt}),e.$evalAsync()))}function w(){e.isFocused||(e.isFocused=!0,c.disabled||(e.backspaceFocus=!1))}function b(){e.isFocused=!1,x||g(),I("blur"),e.$evalAsync()}function I(r){var o=new RegExp(r).test(et.saveTrigger),i=et.newItem&&e.query,u=angular.isNumber(e.selectorPosition),s=e.order[e.selectorPosition],l=t.reject(),a="blur"!==r||e.query||!et.newItem;o&&(i||u&&s)&&(e.showLoader=!0,l=t.when("blur"!==r&&s||e.query&&Y(e.$parent,{$query:e.query}))),l.then(function(t){a&&e.addItem(t)}).finally(function(){var t=e.order.length-1;e.selectorPosition===t&&z(J,0),et.newItemFn&&!u||n(angular.noop),W()})}function S(){var e=x&&d.$modelValue&&d.$modelValue.length?"":K;G.attr("placeholder",e)}function V(t){return l.getValue(y,t,e.$parent,O)}function F(t){return l.getValue(y,t,e.$parent,E)}function k(t){return String(l.getValue(y,t,e.$parent,L))}function Q(t){return l.getValue(y,t,e.$parent,C)}function R(t){return l.getValue(y,t,e.$parent,P)||""}function j(t){return l.getValue(q,t,e.$parent,A)}function U(r,o){var i=H(e.$parent,{$query:r,$selectedAs:o}),u=0;return e.selectorPosition="prompt"===et.newItem?!1:0,r||o||(e.oldQuery=null),m&&(i.$promise&&!i.$resolved||angular.isFunction(i.then))&&(n.cancel(m),u=et.debounce),m=n(function(){return e.showLoader=!0,t.when(i.$promise||i).then(function(t){if(!o){var n=x?e.output:[],i=lt(l.objToArr(t),r,k,at(e.$parent)),u=l.intersection(i,n,V,V,!0),s=j(u);e.groups=X(s),B()}return t}).finally(function(){e.showLoader=!1})},u)}function B(){var t,n,r,o=[],i=0;e.order=[],e.groupPos={};for(n in e.groups)e.groups.hasOwnProperty(n)&&"$"!=n.charAt(0)&&o.push(n);for(angular.version.major<=1&&angular.version.minor<=3&&o.sort(),t=0;t=T)return o.addClass("limited"),void n(function(){o.removeClass("limited")},150);var r=e.groups[R(t)]=e.groups[R(t)]||[],i=E?F(t):t;r.splice(r.indexOf(t),1),x?d.$setViewValue(angular.isArray(d.$modelValue)?d.$modelValue.concat(i):[i]):(d.$setViewValue(i),g()),l.groupsIsEmpty(e.groups)&&(e.groups={}),x||et.closeList||W({query:!0}),e.oldQuery=e.oldQuery||e.query,e.query="",e.backspaceFocus=!1}},e.removeItem=function(t){c.disabled||!x&&!e.inputHide||(x&&t>=0&&(v=d.$modelValue[t],d.$modelValue.splice(t,1),d.$setViewValue([].concat(d.$modelValue))),x||(v=d.$modelValue,f(),et.cleanModel&&d.$setViewValue(void 0)),nt||!x&&e.backspaceFocus||(e.query=rt(v,h,k)),nt=!1,x&&et.closeList&&W({query:!0}))},e.setSelection=function(t){N||e.selectorPosition===t?N=!1:z(J,t)},e.keyUp=function(t){switch(t.keyCode){case 8:e.query.length||x&&e.output.length||W()}},e.keyDown=function(t){var n=0,r=e.order.length-1;switch(t.keyCode){case 38:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n,z(J,e.selectorPosition===n?r:e.selectorPosition-1),N=!0;break;case 40:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n-1,z(J,e.selectorPosition===r?n:e.selectorPosition+1),N=!0,e.query.length||e.isOpen||U(),e.inputHide&&f();break;case 37:case 39:break;case 13:I("enter"),t.preventDefault();break;case 27:x||(g(),et.cleanModel&&d.$setViewValue(v)),W();break;case 8:if(!e.query.length){if((!x||tt)&&(e.backspaceFocus=!0),e.backspaceFocus&&e.output){e.removeItem(e.output.length-1),tt&&t.preventDefault();break}e.backspaceFocus=!e.backspaceFocus;break}default:return e.backspaceFocus=!1,!1}},e.getSearchLabel=function(t){var n=k(t);return ot(n,e.oldQuery||e.query,t,it(e.$parent))},e.getDropdownLabel=function(t){var n=k(t);return ut(n,e.oldQuery||e.query,t,st(e.$parent))},e.getDisableWhen=Q,x&&(d.$isEmpty=function(e){return!e||!e.length}),W(),o[0].addEventListener("click",$,!0),o.on("focus",w),o.on("blur",b)}}}}]),angular.module("oi.select").filter("oiSelectCloseIcon",["$sce",function(e){return function(t){var n='×';return e.trustAsHtml(t+n)}}]).filter("oiSelectHighlight",["$sce",function(e){return function(t,n){var r;return n.length>0||angular.isNumber(n)?(t=t.toString(),n=n.toString().replace(/\s+.*/,"").replace(/\\/g,"\\\\"),r=t.replace(new RegExp(n,"gi"),"$&")):r=t,e.trustAsHtml(r)}}]).filter("oiSelectAscSort",function(){function e(e,t,n,r){var o,i,u,s,l=[],a=[],c=[];if(t){for(t=String(t).replace(/\s+.*/,"").replace(/\\/g,"\\\\"),o=0,u=!1;o -

Clean model [depricated]

-

Clean model on blur. Angular select doesn't clean the model on blur. Use external function for cleaning the model. F.e.: ng-click="bundle = undefined"

+

Clean model

+

Clean model by click

Clean model [depricated] placeholder="Select" >
-
- -
diff --git a/src/directives.js b/src/directives.js index aac7324..71a6446 100644 --- a/src/directives.js +++ b/src/directives.js @@ -42,11 +42,11 @@ angular.module('oi.select') placeholderFn = $interpolate(attrs.placeholder || ''), optionsFn = $parse(attrs.oiSelectOptions), keyUpDownWerePressed = false, - matchesWereReset = false, - cleanModel = true; + matchesWereReset = false; var timeoutPromise, - lastQuery; + lastQuery, + removedItem; return function(scope, element, attrs, ctrl) { var inputElement = element.find('input'), @@ -80,6 +80,10 @@ angular.module('oi.select') }; } + if (options.cleanModel) { + element.addClass('cleanMode'); + } + var unbindFocusBlur = oiUtils.bindFocusBlur(element, inputElement); if (angular.isDefined(attrs.autofocus)) { @@ -219,15 +223,12 @@ angular.module('oi.select') resetMatches({query: true}); } - cleanModel = false; scope.oldQuery = scope.oldQuery || scope.query; scope.query = ''; scope.backspaceFocus = false; }; scope.removeItem = function removeItem(position) { - var removedItem; - if (attrs.disabled || !multiple && !scope.inputHide) return; if (multiple && position >= 0) { @@ -239,6 +240,10 @@ angular.module('oi.select') if (!multiple) { removedItem = ctrl.$modelValue; cleanInput(); + + if (options.cleanModel) { + ctrl.$setViewValue(undefined); + } } if (!editItemCorrect && (multiple || !scope.backspaceFocus)) { @@ -305,6 +310,10 @@ angular.module('oi.select') case 27: /* esc */ if (!multiple) { restoreInput(); + + if (options.cleanModel) { + ctrl.$setViewValue(removedItem); + } } resetMatches(); break; @@ -404,14 +413,9 @@ angular.module('oi.select') scope.isFocused = false; if (!multiple) { - if (options.cleanModel && !scope.inputHide) { - ctrl.$setViewValue(undefined); - } restoreInput(); } - cleanModel = true; - saveOn('blur'); scope.$evalAsync(); } @@ -433,7 +437,6 @@ angular.module('oi.select') .then(function(data) { if (isItemSave) { scope.addItem(data); - cleanModel = true; } }) .finally(function() { diff --git a/src/style.styl b/src/style.styl index 3d84403..bdaf797 100644 --- a/src/style.styl +++ b/src/style.styl @@ -118,12 +118,18 @@ oi-select border-color #fff text-align left - &-remove - display none - &:not(:active) background none + &:not([multiple]):not(.cleanMode) + .select + &-search + &-list + &-item + &_selection + &-remove + display none + &:after content "" position absolute