Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions dist/angular-selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ angular.module('selectize', []).value('selectizeConfig', {}).directive("selectiz
return {
restrict: 'EA',
require: '^ngModel',
scope: { ngModel: '=', config: '=?', options: '=?', ngDisabled: '=', ngRequired: '&' },
scope: { ngModel: '=', config: '=?', options: '=?', ngDisabled: '=', ngRequired: '&', clearOption: '@' },
link: function(scope, element, attrs, modelCtrl) {

var selectize,
Expand Down Expand Up @@ -39,7 +39,6 @@ angular.module('selectize', []).value('selectizeConfig', {}).directive("selectiz

selectize.addOption(curr, true);

selectize.refreshOptions(false); // updates results if user has entered a query
setSelectizeValue();
}

Expand All @@ -57,10 +56,20 @@ angular.module('selectize', []).value('selectizeConfig', {}).directive("selectiz
}

settings.onChange = function(value) {

var value = angular.copy(selectize.items);

if (settings.maxItems == 1) {
value = value[0]
value = value[0];

if(!isEmpty(scope.clearOption)) {
if(value == scope.clearOption) {
selectize.clear();
return;
}
}
}

modelCtrl.$setViewValue( value );

if (scope.config.onChange) {
Expand All @@ -81,6 +90,15 @@ angular.module('selectize', []).value('selectizeConfig', {}).directive("selectiz
settings.onInitialize = function() {
selectize = element[0].selectize;

if(!isEmpty(scope.clearOption)) {
var clearOption = {};

clearOption[ settings.valueField ] = scope.clearOption;
clearOption[ settings.labelField ] = scope.clearOption;

scope.options.splice(0, 0, clearOption);
}

setSelectizeOptions(scope.options);

//provides a way to access the selectize element from an
Expand Down