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

fix($observe): check if the attribute is undefined #9720

Closed
wants to merge 1 commit into from
Closed

fix($observe): check if the attribute is undefined #9720

wants to merge 1 commit into from

Conversation

Puigcerber
Copy link
Contributor

Check if the attribute is undefined before manually applying the function because if not an undefined
property is added to the scope of the form controller when the input control does not have a name.

Closes #9707

#ngEurope /cc @rodyhaddad @vojtajina

@mary-poppins
Copy link

I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS.

Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match.

If you signed the CLA as a corporation, please let us know the company's name.

Thanks a bunch!

PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@Puigcerber
Copy link
Contributor Author

Hi @mary-poppins! I have just signed the CLA. Cheers.

@Puigcerber Puigcerber changed the title fix($observe): check if the attribute is undefined before manually applying the function fix($observe): check if the attribute is undefined Oct 21, 2014
@@ -1073,7 +1073,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {

listeners.push(fn);
$rootScope.$evalAsync(function() {
if (!listeners.$$inter) {
if (!listeners.$$inter && typeof attrs[key] !== 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the name attribute is set, but empty? Does the condition apply?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked it and an empty name does not create a property in the scope.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using attrs.hasOwnProperty(key) instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I have updated my commit ;)

Check if the attribute is undefined before manually applying the function because if not an undefined
property is added to the scope of the form controller when the input control does not have a name.

Closes #9707
@caitp
Copy link
Contributor

caitp commented Oct 22, 2014

I am a fan of this, lets get this in. @Puigcerber you signed with pablo85@... right?

@@ -1331,6 +1331,11 @@ describe('input', function() {
expect(scope.name).toEqual('adam');
});

it('should not add the property to the scope if name is undefined', function() {
compileInput('<input type="text" ng-model="name" />');
expect(scope.form['undefined']).toBeUndefined();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what we should do though, is spy on the $addControl and $$renameControl methods of the form though... I think we'd have to rewrite it to not use compileInput to make that work

@caitp caitp closed this in 531a8de Oct 22, 2014
@caitp
Copy link
Contributor

caitp commented Oct 23, 2014

CLA verified by Max Sills and George Lu

@Puigcerber
Copy link
Contributor Author

Hi @caitp! Sorry I didn't answer before but I was in the conference. It feels good to have contributed to the core for first time and I hope it's not the last. Thanks for merging!

@caitp
Copy link
Contributor

caitp commented Oct 24, 2014

Right on, thanks for the patch =] Hope to see more of that from you in the future!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ngModel renames inputs with no "name" attribute to "undefined"
5 participants