Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
Have "val-required" included with "val-equalto" in order to match beh…
Browse files Browse the repository at this point in the history
…avior of the data validation attributes in C#.
  • Loading branch information
mdekrey committed Apr 10, 2015
1 parent de14f7a commit 1035b35
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@
&& (!options.parameters.regex || !!(new RegExp(options.parameters.regex).exec(val)));
});
validationProvider.addValidator("equalto",(val: string, options: OptionsAIP<NamedAttributes, EqualToInjected, EqualToParameters>) => {
if (!val)
return true;
// intentionally not passing for !val - MS's server-side validation does not require the [Required] attribute, so we won't require val-required, either.
var prefix = getModelPrefix(options.attributes.name),
other = options.parameters.other,
fullOtherName = appendModelPrefix(other, prefix),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,28 @@
expect(sce.getTrustedHtml(valScope.messages[fieldName]['equalto'])).to.equal(message);
}

it('passes a null value',() => {
it('fails a null value that does not match',() => {
scope.target = null;
scope.$digest();

isValid();
isInvalid();
});

it('passes an empty value',() => {
it('fails an empty value that does not match',() => {
scope.target = '';
scope.$digest();

isValid();
isInvalid();
});

it('passes an empty value that does match',() => {
scope.target = '';
scope.other = '';
scope.$digest();

isInvalid();
});

it('fails an incorrect value',() => {
scope.target = '0';
scope.$digest();
Expand Down
2 changes: 0 additions & 2 deletions js/angular.unobtrusive.validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,6 @@ var ResponsivePath;
return (!options.parameters.min || val.length >= parseInt(options.parameters.min)) && (!options.parameters.nonalphamin || nonalphamin(val, parseInt(options.parameters.nonalphamin))) && (!options.parameters.regex || !!(new RegExp(options.parameters.regex).exec(val)));
});
validationProvider.addValidator("equalto", function (val, options) {
if (!val)
return true;
var prefix = getModelPrefix(options.attributes.name), other = options.parameters.other, fullOtherName = appendModelPrefix(other, prefix), element = options.injected.validation.dataValue(options.scope, fullOtherName);
return element == val;
}, ['validation']);
Expand Down
2 changes: 1 addition & 1 deletion js/angular.unobtrusive.validation.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/angular.unobtrusive.validation.min.js.map

Large diffs are not rendered by default.

0 comments on commit 1035b35

Please sign in to comment.