Skip to main content

Bug Tracker

Side navigation

#7360 closed bug (wontfix)

Opened October 30, 2010 04:54PM UTC

Closed October 30, 2010 07:27PM UTC

Last modified March 10, 2012 11:28AM UTC

.val(undefined) returns jQuery obj instead of value

Reported by: jonny.fillmore@uk2group.com Owned by:
Priority: undecided Milestone:
Component: attributes Version: 1.4.3
Keywords: regression Cc:
Blocked by: Blocking:
Description

In jQuery 1.4.3 the 'val' function behaves inconsistently if an undefined value is passed in explicitly. If you have a wrapper around this method that mirrors the "if param is undefined, return value" convention then it will no longer work due to 1.4.3 checking the number of parameters given, not the first param's value.

For example:

1.4.2


1341 val: function( value ) {

1342 if ( value === undefined ) {

1343 var elem = this[0];

item = $('input[type=text]');

item.val("foo");

value = undefined;

item.val(undefined); returns "foo"

item.val(value); returns "foo"

item.val(); // returns "foo"

1.4.3


1534 val: function( value ) {

1535 if ( !arguments.length ) {

1536 var elem = this[0];

item = $('input[type=text]');

item.val("foo");

value = undefined;

item.val(undefined); returns [<input type="text"...>]

item.val(value); returns [<input type="text"...>]

item.val(); // returns "foo"

Attachments (0)
Change History (2)

Changed October 30, 2010 07:27PM UTC by snover comment:1

component: unfiledattributes
keywords: → regression
milestone: 1.5
resolution: → wontfix
status: newclosed

This is by design. See #4130.

Changed August 09, 2011 09:42AM UTC by victor comment:2

As a consequence of this issue, the proper 'val' substitution should look as follows:

(function () {
    if (!jQuery || !jQuery.fn.val)
        return;

    var original = jQuery.fn.val;
    jQuery.fn.val = function (value) {

	... do something ...

        // jQuery ticket #7360 (http://bugs.jquery.com/ticket/7360)
        return typeof(value) !== "undefined" ? original.call(this, value) : original.call(this);
    };
})();