Skip to content

Commit

Permalink
Fixes $watch on options model
Browse files Browse the repository at this point in the history
The reference to $scope.options was being overwritten. This saves what's returned from the generateOptions function and pushes it to an emptied scope.options while keeping its reference.

Resolves machineboy2045#63
  • Loading branch information
Michael Teixeira committed Mar 31, 2015
1 parent 4662161 commit d1b81ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Binary file added .DS_Store
Binary file not shown.
17 changes: 13 additions & 4 deletions dist/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,17 @@ angular.module('selectize', []).value('selectizeConfig', {}).directive("selectiz

// ngModel (ie selected items) is included in this because if no options are specified, we
// need to create the corresponding options for the items to be visible
scope.options = generateOptions( (scope.options || config.options || scope.ngModel).slice() );
scope.generatedOptions = generateOptions( (scope.options || config.options || scope.ngModel).slice() );
scope.options.length = 0;
scope.generatedOptions.forEach(function (item) {
scope.options.push(item);
});

var angularCallback = config.onInitialize;

config.onInitialize = function(){
selectize = element[0].selectize;
selectize.addOption(scope.options)
selectize.addOption(scope.generatedOptions)
selectize.setValue(scope.ngModel)

//provides a way to access the selectize element from an
Expand All @@ -105,9 +109,14 @@ angular.module('selectize', []).value('selectizeConfig', {}).directive("selectiz
}

scope.$watch('options', function(){
scope.generatedOptions = generateOptions( (scope.options || config.options || scope.ngModel).slice() );
scope.options.length = 0;
scope.generatedOptions.forEach(function (item) {
scope.options.push(item);
});
selectize.clearOptions();
selectize.addOption(scope.options)
selectize.setValue(scope.ngModel)
selectize.addOption(scope.generatedOptions);
selectize.setValue(scope.ngModel);
}, true);

scope.$watchCollection('ngModel', updateSelectize);
Expand Down

0 comments on commit d1b81ba

Please sign in to comment.