Skip to content

Commit

Permalink
Changing false validations to return invalid value so that they can b…
Browse files Browse the repository at this point in the history
…e used. Adding tests. This is an addition to PR angular-ui#149
  • Loading branch information
Matt M committed Feb 1, 2014
1 parent 4180b18 commit 440577b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions modules/validate/test/validateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<input name="input" ng-model="value" ui-validate="\'validate($value)\'">', scope);
expect(scope.form.input.$valid).toBeFalsy();
expect(scope.value).toEqual(testValue);
expect(inputElm.val()).toEqual(testValue);
}));
});

describe('validation on model change', function () {
Expand Down Expand Up @@ -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('<input name="input" ng-model="value" ui-validate="{key1 : \'validate1($value)\', key2 : \'validate2($value)\', key3 : \'validate2($value)\'}">', 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(){
Expand Down
2 changes: 1 addition & 1 deletion modules/validate/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 440577b

Please sign in to comment.