angular-selectize2
Advanced tools
Comparing version 1.2.2 to 1.2.3
{ | ||
"name": "angular-selectize2", | ||
"version": "1.2.1", | ||
"version": "1.2.3", | ||
"main" : [ | ||
@@ -5,0 +5,0 @@ "./dist/selectize.js" |
@@ -10,3 +10,3 @@ /** | ||
require: '^ngModel', | ||
scope: {ngModel: '=', config: '=?', options: '=?', ngDisabled: '=', ngRequired: '&'}, | ||
scope: { ngModel: '=', config: '=?', options: '=?', ngDisabled: '=', ngRequired: '&' }, | ||
link: function(scope, element, attrs, modelCtrl) { | ||
@@ -19,5 +19,5 @@ | ||
modelCtrl.$isEmpty = function(val){ | ||
return (val === undefined || val === null || !val.length); //override to support checking empty arrays | ||
} | ||
modelCtrl.$isEmpty = function(val) { | ||
return val === undefined || val === null || !val.length; //override to support checking empty arrays | ||
}; | ||
@@ -31,3 +31,3 @@ function createItem(input) { | ||
function toggle(disabled){ | ||
function toggle(disabled) { | ||
disabled ? selectize.disable() : selectize.enable(); | ||
@@ -38,12 +38,12 @@ } | ||
var isInvalid = (scope.ngRequired() || attrs.required || config.required) && modelCtrl.$isEmpty(scope.ngModel); | ||
modelCtrl.$setValidity('required', !isInvalid) | ||
modelCtrl.$setValidity('required', !isInvalid); | ||
}; | ||
function generateOptions(data){ | ||
if(!data) | ||
function generateOptions(data) { | ||
if (!data) | ||
return []; | ||
data = angular.isArray(data) ? data : [data] | ||
return $.map(data, function(opt){ | ||
data = angular.isArray(data) || angular.isObject(data) ? data : [data] | ||
return $.map(data, function(opt) { | ||
return typeof opt === 'string' ? createItem(opt) : opt; | ||
@@ -53,13 +53,13 @@ }); | ||
function updateSelectize(){ | ||
function updateSelectize() { | ||
validate(); | ||
selectize.$control.toggleClass('ng-valid', modelCtrl.$valid) | ||
selectize.$control.toggleClass('ng-invalid', modelCtrl.$invalid) | ||
selectize.$control.toggleClass('ng-dirty', modelCtrl.$dirty) | ||
selectize.$control.toggleClass('ng-pristine', modelCtrl.$pristine) | ||
selectize.$control.toggleClass('ng-valid', modelCtrl.$valid); | ||
selectize.$control.toggleClass('ng-invalid', modelCtrl.$invalid); | ||
selectize.$control.toggleClass('ng-dirty', modelCtrl.$dirty); | ||
selectize.$control.toggleClass('ng-pristine', modelCtrl.$pristine); | ||
if( !angular.equals(selectize.items, scope.ngModel) ){ | ||
selectize.addOption(generateOptions(scope.ngModel)) | ||
selectize.setValue(scope.ngModel) | ||
if (!angular.equals(selectize.items, scope.ngModel)) { | ||
selectize.addOption(generateOptions(scope.ngModel)); | ||
selectize.setValue(scope.ngModel); | ||
} | ||
@@ -70,7 +70,10 @@ } | ||
onOptionAdd = config.onOptionAdd; | ||
config.onChange = function(){ | ||
if( !angular.equals(selectize.items, scope.ngModel) ) | ||
scope.$evalAsync(function(){ | ||
var value = selectize.items.slice(); | ||
config.onChange = function() { | ||
if(scope.disableOnChange) | ||
return; | ||
if (!angular.equals(selectize.items, scope.ngModel)) | ||
scope.$evalAsync(function() { | ||
var value = angular.copy(selectize.items); | ||
if (config.maxItems == 1) { | ||
@@ -85,39 +88,46 @@ value = value[0] | ||
} | ||
} | ||
}; | ||
config.onOptionAdd = function(value, data) { | ||
if( scope.options.indexOf(data) === -1 ) | ||
if( scope.options.indexOf(data) === -1 ) { | ||
scope.options.push(data); | ||
if (onOptionAdd) { | ||
onOptionAdd.apply(this, arguments); | ||
if (onOptionAdd) { | ||
onOptionAdd.apply(this, arguments); | ||
} | ||
} | ||
}; | ||
if(scope.options){ | ||
// replace scope options with generated options while retaining a reference to the same array | ||
scope.options.splice(0, scope.options.length, generateOptions(scope.options) ); | ||
}else{ | ||
// default options = [ngModel] if no options specified | ||
scope.options = generateOptions( angular.copy(scope.ngModel) ); | ||
} | ||
// 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() ); | ||
var angularCallback = config.onInitialize; | ||
config.onInitialize = function(){ | ||
config.onInitialize = function() { | ||
selectize = element[0].selectize; | ||
selectize.addOption(scope.options) | ||
selectize.setValue(scope.ngModel) | ||
selectize.addOption(scope.options); | ||
selectize.setValue(scope.ngModel); | ||
//provides a way to access the selectize element from an | ||
//angular controller | ||
if(angularCallback){ | ||
if (angularCallback) { | ||
angularCallback(selectize); | ||
} | ||
scope.$watch('options', function(){ | ||
scope.$watch('options', function() { | ||
scope.disableOnChange = true; | ||
selectize.clearOptions(); | ||
selectize.addOption(scope.options) | ||
selectize.setValue(scope.ngModel) | ||
selectize.addOption(scope.options); | ||
selectize.setValue(scope.ngModel); | ||
scope.disableOnChange = false; | ||
}, true); | ||
scope.$watchCollection('ngModel', updateSelectize); | ||
scope.$watch('ngDisabled', toggle); | ||
} | ||
}; | ||
@@ -132,5 +142,4 @@ element.selectize(config); | ||
}); | ||
} | ||
}; | ||
}]); |
{ | ||
"name": "angular-selectize2", | ||
"description": "angular-selectize rightster fork", | ||
"version": "v1.2.2", | ||
"description": "This is an Angular.js directive for Brian Reavis's selectize jQuery plugin. It supports all of Selectize's features", | ||
"version": "v1.2.3", | ||
"private": false | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
8639
120