Bug Tracker

Modify

Ticket #4130 (closed bug: fixed)

Opened 4 years ago

Last modified 15 months ago

.val() should not return null as a value

Reported by: ptran123 Owned by: dmethvin
Priority: minor Milestone: 1.4.3
Component: attributes Version: 1.4.2
Keywords: val() Cc:
Blocking: Blocked by:

Description

I have an object with properties obj.FirstName and obj.LastName. FirstName is "mickey" and LastName is null. When I use $("#lastNameTextBox").val(obj.LastName), it displays null in the textbox. It should not display anything if the value is null. This logic worked OK with version 1.2.6. However, version 1.3.1 is showing null in this textbox.

Attachments

HTMLPage.htm Download (648 bytes) - added by ptran123 4 years ago.

Change History

Changed 4 years ago by ptran123

comment:1 Changed 4 years ago by ptran123

FYI, I'm using JSON.parse() from www.json.org to create the object.

comment:2 Changed 4 years ago by dmethvin

The 1.2.6 behavior was actually a bug. The $("#x").val(null) was treated as a getter rather than a setter, meaning it wasn't chainable when it should have been. If the value passed to .val() has the potential to be null or undefined, the best way to handle it is to use something like $("#lastNameTextBox").val(obj.LastName || "").

comment:3 Changed 4 years ago by dmethvin

  • Priority changed from major to minor
  • Component changed from unfilled to core

comment:4 Changed 3 years ago by dmethvin

  • Component changed from core to attributes

comment:5 Changed 3 years ago by dmethvin

  • need changed from Review to Commit
  • Owner set to dmethvin

Clarification for this bug: the remaining issue with 1.4.3 is that .val(undefined) is not chainable. This patch makes it chainable and defines it as .val("").

Patch:  http://github.com/dmethvin/jquery/commit/43b06cf1c8694c953831b3509a1280b762763134

comment:6 Changed 3 years ago by john

  • Status changed from new to closed
  • Version changed from 1.3.1 to 1.4.2
  • Resolution set to fixed
  • Milestone changed from 1.3.2 to 1.4.3

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.