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

fix(jqLite): Chrome specific issue for <select required> #7136

Merged
merged 2 commits into from
Jul 8, 2014

Conversation

lgalfaso
Copy link
Contributor

Request Type: bug, regression

How to reproduce: Look at #6828

Component(s): jqLite

Impact: medium

Complexity: small

This issue is related to: regression

Detailed Description:

When using Chrome and adding a <option selected="selected"> to a <select required> then the new added option is not selected

Other Comments:

@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#7136)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@caitp
Copy link
Contributor

caitp commented Apr 16, 2014

how was this related to a performance regression?

@lgalfaso
Copy link
Contributor Author

@caitp You are right, I try to use the template and thought that "performance/regression" was a performance issue or a regression. Just fixed it

@lgalfaso
Copy link
Contributor Author

I do not like this patch, just too hacky. Will close it until I find a better solution

@lgalfaso lgalfaso closed this Apr 20, 2014
@lgalfaso lgalfaso reopened this Apr 20, 2014
@lgalfaso
Copy link
Contributor Author

The patch at 9c66807 is a lot better than the previous patch (and it fixes the issue at the right location)

@chrisirhc
Copy link
Contributor

+1 to this patch. Works for resolving #7202 which causes workaround on #638 (comment) to break.


Edit: I take that back. This patch doesn't work for me. I was testing on the wrong version of AngularJS when I reported that it works.

element.attr('selected') returns undefined even when element[0].getAttribute('selected') === 'selected' on jQuery 2.0.3 with jQuery Migrate.

@chrisirhc
Copy link
Contributor

I used:

        if (element[0].hasAttribute('selected')) {
          element[0].selected = true;
        }

.attr('selected') is broken by jQuery-migrate and some versions of jQuery (e.g. 1.7.2). See http://jsfiddle.net/sirhc/VSqQf/

@chrisirhc
Copy link
Contributor

@lgalfaso , please consider using hasAttribute in your fix, otherwise this change won't fix users that are on some versions of jQuery or using jQuery-Migrate.

@lgalfaso
Copy link
Contributor Author

@mzgol can you please comment on #7136 (comment) ?

@@ -171,6 +171,9 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
$element.val(value);
if (unknownOption.parent()) unknownOption.remove();
}
if (element.attr('selected') === 'selected') {
Copy link
Contributor

Choose a reason for hiding this comment

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

hasAttribute('selected') is likely safer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@IgorMinar there is no hasAttribute at the jqLite level, two options, do
element[0].hasAttribute && element[0].hasAttribute('selected') or
isDefined(element.attr('selected'))

Which alternative you think it is best?

Copy link
Contributor

Choose a reason for hiding this comment

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

element[0].hasAttribute('selected') is fine

@IgorMinar
Copy link
Contributor

lgtm

@mgol
Copy link
Member

mgol commented Jun 10, 2014

@lgalfaso

@mzgol can you please comment on #7136 (comment) ?

TBH I'd rather just say we support jQuery >= 1.8 and that we don't support jQuery Migrate than try to bypass the method made for what we're trying to do here just because older jQuery versions had broken semantics with respect to treating .attr/.prop.

@IgorMinar
Copy link
Contributor

@lgalfaso I think that @mzgol is right. unless the version of jQuery are testing against is affected by this, we should just use jQuery apis.

Also can you please add a comment that this is to work around https://code.google.com/p/chromium/issues/detail?id=381459 into the code?

Can you merge this in?

@chrisirhc
Copy link
Contributor

Take note that jQuery >= 1.9 with jQuery Migrate won't work if you use the jQuery APIs (as I mentioned above).

jQuery Migrate helps users migrate from pre-1.9 to jQuery >= 1.9, so if users add jQuery Migrate to upgrade to jQuery >= 1.8 to upgrade to say jQuery 2.0, the API will be broken (for this PR).

If you do use jQuery APIs for this PR, users that are now dependent on jQuery < 1.8 or jQuery Migrate (jQuery >= 1.9) are now restricted to jQuery >= 1.8 && jQuery < 1.9 . That is unless they rewrite their application to fix all the breaking jQuery API changes in jQuery 1.9 so they can avoid using jQuery Migrate.

@IgorMinar
Copy link
Contributor

We currently don't test against the migrate plugin and I'm quite sure that
there are many other places where we use jquery prop() api in a way that
would be incompatible with jquery 1.8.
On Jul 8, 2014 9:46 AM, "Chris Chua" notifications@github.com wrote:

Take note that jQuery >= 1.9 with jQuery Migrate won't work if you use the
jQuery APIs (as I mentioned above).

jQuery Migrate helps users migrate from pre-1.9 to jQuery >= 1.9, so if
users add jQuery Migrate to upgrade to jQuery >= 1.8 to upgrade to say
jQuery 2.0, the API will be broken (for this PR).

If you do use jQuery APIs for this PR, users that are now dependent on
pre-jQuery 1.8 are now restricted to jQuery >= 1.8 && jQuery < 1.9 .
That is unless they rewrite their application to fix all the breaking
jQuery API changes in jQuery 1.9 so they can avoid using jQuery Migrate.


Reply to this email directly or view it on GitHub
#7136 (comment).

When adding a new <option> element, if the DOM of this option element
states that the element is marked as `selected`, then select the new
<option> element

Closes angular#6828
@chrisirhc
Copy link
Contributor

The migrate plugin is forward compatible, and the use of the .prop API is encouraged. The use of .attr is what's broken and incompatible in past jQuery versions, especially when the .attr is checking something that's been set in .prop.

Conflicts:
	src/ng/directive/select.js
@IgorMinar
Copy link
Contributor

If that's the case the we can perform the attribute check via the raw DOM
api. But I still doubt in full compatibility with jquery migrate.

On Tue, Jul 8, 2014, 10:14 AM Chris Chua notifications@github.com wrote:

The migrate plugin is forward compatible, and the use of the .prop API is
encouraged. The use of .attr is what's broken and incompatible in past
jQuery versions, especially when the .attr is checking something that's
been set in .prop.


Reply to this email directly or view it on GitHub
#7136 (comment).

@chrisirhc
Copy link
Contributor

I understand that doubt since you're not testing against the migrate plugin.

I'm just trying to drive at the point that I feel there are a number of people dependent on jQuery Migrate when upgrading jQuery and this seems trivial enough to pick the safer option.

lgalfaso added a commit that referenced this pull request Jul 8, 2014
fix(jqLite): Chrome specific issue for `<select required>`
@lgalfaso lgalfaso merged commit 14e3ba8 into angular:master Jul 8, 2014
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.

10 participants