Skip to content

Update val.js #1531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

Update val.js #1531

wants to merge 6 commits into from

Conversation

johnhoven
Copy link
Contributor

Seeing a behavior change in jQuery('option').val() as reported in http://bugs.jquery.com/ticket/14858. Behavior of .val() was changed which may return insignificant white space when a value attribute is not used.

Seems to have been changed because of this ticket:
http://bugs.jquery.com/ticket/14686
in this commit:
92cbf53#diff-ac2456f6444b226fd09f497031b2f7d2

Since the problem is in IE10/11 and only for an empty value, can we simply return element.text. If an exception is caught, return an empty string?

Seeing a behavior change in jQuery('option').val() as reported in http://bugs.jquery.com/ticket/14858.  Behavior of .val() was changed which may return insignificant white space when a value attribute is not used.

Seems to have been changed because of this ticket:
http://bugs.jquery.com/ticket/14686
in this commit:
92cbf53#diff-ac2456f6444b226fd09f497031b2f7d2

Since the problem is in IE10/11 and only for an empty value, can we simply return element.text.  If an exception is caught, return an empty string?
@dmethvin
Copy link
Member

dmethvin commented Mar 6, 2014

Thanks for investigating this!

Usually we like to steer clear of try/catch, they can mask other problems and they also defeat optimization in several browsers.

You can see the Travis build failed, looks like you need to brush on the style guide. In most cases it's easy to avoid those problems by being really observant about the surrounding style, but some older untouched areas of the code may not be good examples. The guide at http://contribute.jquery.org/style-guide/js/ is the best way to go.

@rwaldron
Copy link
Member

rwaldron commented Mar 6, 2014

This will also require new tests to prove the patch addresses the reported issue.

@dmethvin
Copy link
Member

dmethvin commented Mar 6, 2014

I am wondering if the bug that caused us to originally change the code like this is now gone from IE10/11, because I can't seem to reproduce in either using bare DOM: http://jsfiddle.net/2avmY/1/

@markelog maybe we can back out this patch?

@johnhoven
Copy link
Contributor Author

I can reproduce the originial bug on my laptop here, although I don't have IE10 set to auto-update on that PC.

@dmethvin
Copy link
Member

dmethvin commented Mar 6, 2014

@johnhoven Run an update and see what happens. I'm running 11.0.3 (KB2909921)

Using style guide to update my pull, add a comment as to why I'm using try/catch.
@johnhoven
Copy link
Contributor Author

Checking for updates now.

I noticed the 2.x branch is still using .text (not jQuery.text()).

Regarding preferring not to use try/catch. The only alternative I can see is to continue to use jQuery.text and trimming the result, however I'm not sure that is equivalent. Thoughts?

I'll look in to adding test cases in case you can't pull this update.

Style guide updates.
@timmywil
Copy link
Member

timmywil commented Mar 6, 2014

We should keep using jQuery.text and make needed adjustments for IE11 there.

@johnhoven
Copy link
Contributor Author

From: http://www.w3.org/wiki/HTML/Elements/option

"value = string
Provides a value for element.
If there isn't, the value of an option element is the textContent of the element"

Maybe I'm backwards. Maybe 1.11.0+ is the only version returning the correct value for this option? Opinion?

Given $('<option> </option').val().length maybe the value length really should be 1 (where it is currently 0 in 1.10.1 and 2.x).

@johnhoven
Copy link
Contributor Author

As far as I can tell I'm on latest update of IE 10. Check for updates isn't offering anything. I'll check again in the morning.

From #1531, currently discussing if the result from val() should be equivalent to textContent in this scenario. This test is to be consistent with 1.10.1 and 2.x branches.  It may be that	1.11.0 is the correct branch.

Given that the browser would show an empty option value for this (no white-space long), and that the w3.org spec on option has the same definition for an empty label and value, and that the length of label for the following snippet would be zero, I'll argue that the value shoudd also be a length of zero.
@johnhoven
Copy link
Contributor Author

@dmethvin, I also tried on IE11 at home (11.0.3) and the same problem persists. I looked at your fiddle, and it wasn't value that was the problem, but element.text (which is what lead to the commit which switched to jQuery.text).

I've updated your fiddle to use text: http://jsfiddle.net/2avmY/3/

@dmethvin
Copy link
Member

dmethvin commented Mar 7, 2014

Duh! Yes, I can repro now.

@dmethvin dmethvin modified the milestone: 1.11.1/2.1.1 Mar 14, 2014
return val;
} else {

/* In IE10/11 (at least before a certain version)
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't match our comment style. Multiple lines should start with //; also, ther should be a // Support: IE10-11+ comment just before the workaround code.

@johnhoven
Copy link
Contributor Author

@mzgol, I've reviewed the style guide @dmethvin linked me to again and I'm not sure about the multi-line comments. Do you mean you want something like this:

/*
//
//
*/

A // on every line?

@mgol
Copy link
Member

mgol commented Mar 18, 2014

Maybe we're missing a guide here. I meant without enclosing /* */, just //.
See other comments in the code base to confirm.

Michał Gołębiowski

@scottgonzalez
Copy link
Member

Actually, the style guide specifically says you can use /* */ for multi-line comments. See http://contribute.jquery.org/style-guide/js/#comments

As far as I can tell, this was copied from the original style guide on MediaWiki. I think we should remove this since we never use it, but this isn't the best place to discuss that change.

@dmethvin
Copy link
Member

@johnhoven can we just change jQuery.text( elem ) to jQuery.trim( jQuery.text( elem ) ) instead? I think that's what @timmywil was suggesting.

@johnhoven
Copy link
Contributor Author

Yes, I was thinking trim would be sufficient to avoid the try/catch. I'll
update my build and unit tests when I get home but it looks like it will
work: http://jsfiddle.net/LmCFA/7/

On Wed, Mar 19, 2014 at 2:37 PM, Dave Methvin notifications@github.comwrote:

@johnhoven https://github.com/johnhoven can we just change jQuery.text(
elem ) to jQuery.trim( jQuery.text( elem ) ) instead? I think that's what
@timmywil https://github.com/timmywil was suggesting.

Reply to this email directly or view it on GitHubhttps://github.com//pull/1531#issuecomment-38096847
.


John Hoven
hovenj@gmail.com

@dmethvin
Copy link
Member

I'll make the code change and land the unit test under your name @johnhoven

@dmethvin dmethvin closed this in 541e734 Mar 20, 2014
dmethvin pushed a commit that referenced this pull request Mar 20, 2014
@johnhoven johnhoven deleted the patch-1 branch March 20, 2014 23:52
mescoda pushed a commit to mescoda/jquery that referenced this pull request Nov 4, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants