Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefine empty check. #178

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions dist/angular-selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* https://github.com/machineboy2045/angular-selectize
**/

// jsruok MOD 2017-06-14: isEmpty array check redefined
// jsruok MOD 2019-06-20: selectize.items, scope.ngModel comparison refined

angular.module('selectize', []).value('selectizeConfig', {}).directive("selectize", ['selectizeConfig', function(selectizeConfig) {
return {
restrict: 'EA',
Expand All @@ -17,7 +20,7 @@ angular.module('selectize', []).value('selectizeConfig', {}).directive("selectiz
scope.config = scope.config || {};

var isEmpty = function(val) {
return val === undefined || val === null || !val.length; //support checking empty arrays
return val === undefined || val === null || (val && typeof val === 'object' && !val.length); //support checking empty arrays // MOD: !val.length => (val && typeof val === 'object' && !val.length)
};

var toggle = function(disabled) {
Expand Down Expand Up @@ -51,7 +54,8 @@ angular.module('selectize', []).value('selectizeConfig', {}).directive("selectiz
selectize.$control.toggleClass('ng-dirty', modelCtrl.$dirty);
selectize.$control.toggleClass('ng-pristine', modelCtrl.$pristine);

if (!angular.equals(selectize.items, scope.ngModel)) {
if (settings.maxItems !== 1 && !angular.equals(selectize.items, scope.ngModel) ||
settings.maxItems === 1 && selectize.items[0] != scope.ngModel) { // If maxItems is 1, items is an array and ngModel is a string
selectize.setValue(scope.ngModel, true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"main": "dist/angular-selectize.js",
"description": "This is an Angular.js directive for Brian Reavis's selectize jQuery plugin. It supports all of Selectize's features",
"version": "v3.0.2",
"version": "v3.0.7",
"license": "MIT",
"repository": {
"type": "git",
Expand Down