From 440577bd0c43a199b7c9999700847b6e3943ebd4 Mon Sep 17 00:00:00 2001 From: Matt M Date: Fri, 31 Jan 2014 23:01:26 -0500 Subject: [PATCH] Changing false validations to return invalid value so that they can be used. Adding tests. This is an addition to PR https://github.com/angular-ui/ui-utils/pull/149 --- modules/validate/test/validateSpec.js | 24 ++++++++++++++++++++++++ modules/validate/validate.js | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/validate/test/validateSpec.js b/modules/validate/test/validateSpec.js index 35275a22..411877e2 100644 --- a/modules/validate/test/validateSpec.js +++ b/modules/validate/test/validateSpec.js @@ -47,6 +47,17 @@ describe('uiValidate', function () { expect(scope.form.input.$valid).toBeFalsy(); expect(scope.form.input.$error).toEqual({ validator: true }); })); + + it('should keep the invalid value in model if it is marked as invalid', inject(function () { + + var testValue = 'test123'; + scope.value = testValue; + scope.validate = falseValidator; + var inputElm = compileAndDigest('', scope); + expect(scope.form.input.$valid).toBeFalsy(); + expect(scope.value).toEqual(testValue); + expect(inputElm.val()).toEqual(testValue); + })); }); describe('validation on model change', function () { @@ -96,6 +107,19 @@ describe('uiValidate', function () { expect(scope.form.input.$error.key1).toBeFalsy(); expect(scope.form.input.$error.key2).toBeTruthy(); }); + + it('should show subsequent validation errors as false if the first of multiple validators fails, but the other validations do not fail', function () { + + scope.validate1 = falseValidator; + scope.validate2 = trueValidator; + scope.validate3 = trueValidator; + + compileAndDigest('', scope); + expect(scope.form.input.$valid).toBeFalsy(); + expect(scope.form.input.$error.key1).toBeTruthy(); + expect(scope.form.input.$error.key2).toBeFalsy(); + expect(scope.form.input.$error.key3).toBeFalsy(); + }); }); describe('uiValidateWatch', function(){ diff --git a/modules/validate/validate.js b/modules/validate/validate.js index fb315351..c794b45e 100644 --- a/modules/validate/validate.js +++ b/modules/validate/validate.js @@ -49,7 +49,7 @@ angular.module('ui.validate',[]).directive('uiValidate', function () { } else { // expression is false ctrl.$setValidity(key, false); - return undefined; + return valueToValidate; } }; validators[key] = validateFn;