Skip to content

Commit 4263c27

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 32cf1e0 commit 4263c27

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
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(){

0 commit comments

Comments
 (0)