Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(ngModel): form validation when there is an Object.prototype enume…
Browse files Browse the repository at this point in the history
…rable value

When adding an Object.prototype enumerable property, this should not be confused
as a form error

Closes #12066
  • Loading branch information
lgalfaso committed Jun 11, 2015
1 parent 571bee7 commit 0934b76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ng/directive/ngModel.js
Expand Up @@ -1351,7 +1351,9 @@ function addSetValidityMethod(context) {
function isObjectEmpty(obj) {
if (obj) {
for (var prop in obj) {
return false;
if (obj.hasOwnProperty(prop)) {
return false;
}
}
}
return true;
Expand Down
25 changes: 25 additions & 0 deletions test/ng/directive/ngModelSpec.js
Expand Up @@ -1091,6 +1091,31 @@ describe('ngModel', function() {
}));


it('should be possible to extend Object prototype and still be able to do form validation',
inject(function($compile, $rootScope) {
Object.prototype.someThing = function() {};
var element = $compile('<form name="myForm">' +
'<input type="text" name="username" ng-model="username" minlength="10" required />' +
'</form>')($rootScope);
var inputElm = element.find('input');

var formCtrl = $rootScope.myForm;
var usernameCtrl = formCtrl.username;

$rootScope.$digest();
expect(usernameCtrl.$invalid).toBe(true);
expect(formCtrl.$invalid).toBe(true);

usernameCtrl.$setViewValue('valid-username');
$rootScope.$digest();

expect(usernameCtrl.$invalid).toBe(false);
expect(formCtrl.$invalid).toBe(false);
delete Object.prototype.someThing;

dealoc(element);
}));

it('should re-evaluate the form validity state once the asynchronous promise has been delivered',
inject(function($compile, $rootScope, $q) {

Expand Down

0 comments on commit 0934b76

Please sign in to comment.