From 797aff0230c8c7ded0bb39514101e19826dac066 Mon Sep 17 00:00:00 2001 From: Philipp Burgmer Date: Tue, 2 Feb 2016 17:10:31 +0100 Subject: [PATCH] feat(ngModel): use validator pipeline for validation 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. --- bower.json | 2 +- src/w11k-select.js | 20 +++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/bower.json b/bower.json index 2c085ff..909b1d1 100644 --- a/bower.json +++ b/bower.json @@ -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" }, diff --git a/src/w11k-select.js b/src/w11k-select.js index 37c186b..d5b5ef4 100644 --- a/src/w11k-select.js +++ b/src/w11k-select.js @@ -653,7 +653,6 @@ angular.module('w11k.select').directive('w11kSelect', [ } } - validateRequired(viewValue); updateHeader(); }); } @@ -672,8 +671,6 @@ angular.module('w11k.select').directive('w11kSelect', [ viewValue = []; } - validateRequired(viewValue); - return viewValue; } @@ -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() { @@ -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);