Bug Tracker

Modify

Ticket #7360 (closed bug: wontfix)

Opened 3 years ago

Last modified 15 months ago

.val(undefined) returns jQuery obj instead of value

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

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"

Change History

comment:1 Changed 3 years ago by snover

  • Keywords regression added
  • Resolution set to wontfix
  • Status changed from new to closed
  • Component changed from unfiled to attributes
  • Milestone 1.5 deleted

This is by design. See #4130.

comment:2 Changed 22 months ago by victor

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);
    };
})();

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.