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

Fix bug with required validation error with default value #135

Open
wants to merge 2 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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.idea/*
*.iml
.sass-cache
src/main/webapp/app/bower_components/**
node_modules
!/.idea/runConfigurations/
18 changes: 10 additions & 8 deletions dist/angular-selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ 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
if(angular.isArray(val)) {
return (val.length === 0);
}
return modelCtrl.$isEmpty(val); //call to real Angular function
};

var toggle = function(disabled) {
disabled ? selectize.disable() : selectize.enable();
}
};

var validate = function() {
var isInvalid = (scope.ngRequired() || attrs.required || settings.required) && isEmpty(scope.ngModel);
Expand All @@ -41,20 +44,19 @@ angular.module('selectize', []).value('selectizeConfig', {}).directive("selectiz

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

var setSelectizeValue = function() {
if (!angular.equals(selectize.items, scope.ngModel)) {
selectize.setValue(scope.ngModel, true);
}
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);

if (!angular.equals(selectize.items, scope.ngModel)) {
selectize.setValue(scope.ngModel, true);
}
}
};

settings.onChange = function(value) {
var value = angular.copy(selectize.items);
Expand Down