Skip to content

Commit 664d124

Browse files
author
Matt M
committed
Changing false validations to return invalid value so that they can be used. Adding tests. This is an addition to PR angular-ui#149
1 parent 4180b18 commit 664d124

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

modules/validate/test/validateSpec.js

+24
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ describe('uiValidate', function () {
4747
expect(scope.form.input.$valid).toBeFalsy();
4848
expect(scope.form.input.$error).toEqual({ validator: true });
4949
}));
50+
51+
it('should keep the invalid value in model if it is marked as invalid', inject(function () {
52+
53+
var testValue = 'test123';
54+
scope.value = testValue;
55+
scope.validate = falseValidator;
56+
var inputElm = compileAndDigest('<input name="input" ng-model="value" ui-validate="\'validate($value)\'">', scope);
57+
expect(scope.form.input.$valid).toBeFalsy();
58+
expect(scope.value).toEqual(testValue);
59+
expect(inputElm.val()).toEqual(testValue);
60+
}));
5061
});
5162

5263
describe('validation on model change', function () {
@@ -96,6 +107,19 @@ describe('uiValidate', function () {
96107
expect(scope.form.input.$error.key1).toBeFalsy();
97108
expect(scope.form.input.$error.key2).toBeTruthy();
98109
});
110+
111+
it('should show subsequent validation errors as false if the first of multiple validators fails, but the other validations do not fail', function () {
112+
113+
scope.validate1 = falseValidator;
114+
scope.validate2 = trueValidator;
115+
scope.validate3 = trueValidator;
116+
117+
compileAndDigest('<input name="input" ng-model="value" ui-validate="{key1 : \'validate1($value)\', key2 : \'validate2($value)\', key3 : \'validate2($value)\'}">', scope);
118+
expect(scope.form.input.$valid).toBeFalsy();
119+
expect(scope.form.input.$error.key1).toBeTruthy();
120+
expect(scope.form.input.$error.key2).toBeFalsy();
121+
expect(scope.form.input.$error.key3).toBeFalsy();
122+
});
99123
});
100124

101125
describe('uiValidateWatch', function(){

modules/validate/validate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ angular.module('ui.validate',[]).directive('uiValidate', function () {
4949
} else {
5050
// expression is false
5151
ctrl.$setValidity(key, false);
52-
return undefined;
52+
return valueToValidate;
5353
}
5454
};
5555
validators[key] = validateFn;

0 commit comments

Comments
 (0)