From 719a3d269af04b26cabb6f98973080f7b5c4cc14 Mon Sep 17 00:00:00 2001 From: Will Date: Tue, 4 Aug 2015 08:56:49 -0700 Subject: [PATCH] Closes #46 - prevent onChange getting triggered too many times --- dist/selectize.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dist/selectize.js b/dist/selectize.js index 977c2bb..39bb111 100755 --- a/dist/selectize.js +++ b/dist/selectize.js @@ -64,6 +64,9 @@ angular.module('selectize', []).value('selectizeConfig', {}).directive("selectiz onOptionAdd = config.onOptionAdd; config.onChange = function() { + if(scope.disableOnChange) + return; + if (!angular.equals(selectize.items, scope.ngModel)) scope.$evalAsync(function() { var value = angular.copy(selectize.items); @@ -106,9 +109,11 @@ angular.module('selectize', []).value('selectizeConfig', {}).directive("selectiz } scope.$watch('options', function() { + scope.disableOnChange = true; selectize.clearOptions(); selectize.addOption(scope.options); selectize.setValue(scope.ngModel); + scope.disableOnChange = false; }, true); scope.$watchCollection('ngModel', updateSelectize);