Skip to content

Commit

Permalink
Support Angular 1.3.x & 1.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
machineboy2045 committed Dec 22, 2014
1 parent 3cce27a commit b88c607
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions dist/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
angular.module('selectize', []).value('selectizeConfig', {}).directive("selectize", ['selectizeConfig', function(selectizeConfig) {
return {
restrict: 'EA',
require: 'ngModel',
require: '^ngModel',
scope: {ngModel: '=', config: '=selectize', options: '=?', ngDisabled: '='},
link: function(scope, element, attrs, modelCtrl) {

Expand All @@ -30,19 +30,21 @@ angular.module('selectize', []).value('selectizeConfig', {}).directive("selectiz
disabled ? selectize.disable() : selectize.enable();
}

modelCtrl.$validators.required = function(modelValue, viewValue) {
if(!config.required)
return true;

return !modelCtrl.$isEmpty(modelValue);
var validate = function() {
var isInvalid = config.required && modelCtrl.$isEmpty(scope.ngModel);
modelCtrl.$setValidity('required', !isInvalid)
};

config.onChange = function(){
if( !angular.equals(selectize.items, scope.ngModel) )
modelCtrl.$setViewValue( angular.copy(selectize.items) );
scope.$evalAsync(function(){
modelCtrl.$setViewValue( angular.copy(selectize.items) );
});
}

function updateSelectize(){
validate();

selectize.$control.toggleClass('ng-valid', modelCtrl.$valid)
selectize.$control.toggleClass('ng-invalid', modelCtrl.$invalid)
selectize.$control.toggleClass('ng-dirty', modelCtrl.$dirty)
Expand Down

0 comments on commit b88c607

Please sign in to comment.