Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Commit

Permalink
feat(ngModel): use validator pipeline for validation
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Using the 'new' validators pipeline requires AngularJS 1.3 or newer. bower.json was adjusted. With the next release we drop support for AngularJS 1.2.
  • Loading branch information
Philipp Burgmer committed Feb 2, 2016
1 parent 5dfaff3 commit 797aff0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"ignore": [],
"dependencies": {
"angular": "1.2.x",
"angular": ">= 1.3.0 < 1.6.0",
"w11k-dropdownToggle": "0.2.x",
"angular-bindonce": "0.3.x"
},
Expand Down
20 changes: 7 additions & 13 deletions src/w11k-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@ angular.module('w11k.select').directive('w11kSelect', [
}
}

validateRequired(viewValue);
updateHeader();
});
}
Expand All @@ -672,8 +671,6 @@ angular.module('w11k.select').directive('w11kSelect', [
viewValue = [];
}

validateRequired(viewValue);

return viewValue;
}

Expand All @@ -695,19 +692,16 @@ angular.module('w11k.select').directive('w11kSelect', [
}

function validateRequired(viewValue) {
var valid = false;

if (scope.config.required === true && viewValue.length > 0) {
valid = true;
}
else if (scope.config.required === false) {
valid = true;
if (scope.config.multiple === true && scope.config.required === true && viewValue.length === 0) {
return false;
}

controller.$setValidity('required', valid);
if (valid) {
return viewValue;
if (scope.config.multiple === false && scope.config.required === true && viewValue === undefined) {
return false;
}

return true;
}

function isEmpty() {
Expand All @@ -722,7 +716,7 @@ angular.module('w11k.select').directive('w11kSelect', [
controller.$render = render;
controller.$formatters.push(external2internal);

controller.$parsers.push(validateRequired);
controller.$validators.required = validateRequired;
controller.$parsers.push(internal2external);


Expand Down

0 comments on commit 797aff0

Please sign in to comment.