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

[htmlAnchorDirective] name on achor tag reloads the UI #6554

Closed
rajeshsegu opened this issue Mar 5, 2014 · 6 comments
Closed

[htmlAnchorDirective] name on achor tag reloads the UI #6554

rajeshsegu opened this issue Mar 5, 2014 · 6 comments

Comments

@rajeshsegu
Copy link

Anchor tag with non empty name, reloads the page:

<a name='http://yahoo.com' value="value=4">link</a> 

As per angular source code, does not comply with the ngClick unit test case behaviour. ( Might have leaked trough since we don't assert if the reload happened )

it('should execute ng-click but not reload when href empty string and name specified', function() {
          element(by.id('link-4')).click();
          expect(element(by.model('value')).getAttribute('value')).toEqual('4');
          expect(element(by.id('link-4')).getAttribute('href')).toBe('');
        });

Looks like it leaked trough the source code via commit @ f3de5b6

As per W3Schools http://www.w3schools.com/tags/att_a_name.asp

The <a> name attribute is not supported in HTML5. Use the id attribute instead.

Why does angular have to bother about handling "name" when its not supported by HTML5 ? Personally, it seems like a specific case quick fix, rather than a generic fix.

I would happy to submit code if this has not been addressed as of today.

@lord2800
Copy link

lord2800 commented Mar 5, 2014

Because the a tag does support name in HTML4.

@rajeshsegu
Copy link
Author

@lord2800 Then I suppose we might need to change the unit case to reflect the behavior.

@davidjnelson davidjnelson self-assigned this Mar 5, 2014
@davidjnelson davidjnelson added this to the Backlog milestone Mar 5, 2014
@davidjnelson davidjnelson removed their assignment Mar 5, 2014
@davidjnelson davidjnelson modified the milestones: 1.3.x, Backlog Mar 5, 2014
@lord2800
Copy link

lord2800 commented Mar 6, 2014

I believe that is the case--based on the commit @ f3de5b6. From what I read of the commit and the message, this test is now wrong.

@btford btford removed the gh: issue label Aug 20, 2014
@caitp
Copy link
Contributor

caitp commented Sep 9, 2014

I think the test passes simply because $location is not injected --- so the test isn't really accurate anyways.

I don't think we're going to end up "fixing" the page-reload thing, because @kseamon thinks we need it, but we can make the test more accurate.

In any case, you should be able to prevent the page-reload by calling preventDefault() on the $event object in your ng-click handler

@caitp caitp self-assigned this Sep 9, 2014
@caitp
Copy link
Contributor

caitp commented Sep 10, 2014

hmm, from karls commit message, event delegation might work better for this (but I can't remember if we decided to go with event delegation for ngClick or not)

caitp added a commit to caitp/angular.js that referenced this issue Sep 22, 2014
This test is incorrectly acting as documentation that the anchor tag directive will preventDefault on
clicks on elements with a name. This has not been the case ever since f3de5b6

Closes angular#6554
petebacondarwin referenced this issue Oct 1, 2014
Change the a directive to link and hookup a click event only when
there is no href or name in the template element.
In a large Google app, this results in about 800 fewer registrations,
saving a small but measurable amount of time and memory.

Closes #5362
@petebacondarwin
Copy link
Contributor

Closing as this is a dupe of #6273

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