Bug Tracker

Opened 10 years ago

Closed 9 years ago

Last modified 7 years ago

#4130 closed bug (fixed)

.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:
Blocked by: Blocking:

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 (1)

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

Download all attachments as: .zip

Change History (7)

Changed 10 years ago by ptran123

Attachment: HTMLPage.htm added

comment:1 Changed 10 years ago by ptran123

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

comment:2 Changed 10 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 10 years ago by dmethvin

Component: unfilledcore
Priority: majorminor

comment:4 Changed 9 years ago by dmethvin

Component: coreattributes

comment:5 Changed 9 years ago by dmethvin

need: ReviewCommit
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 9 years ago by john

Milestone: 1.3.21.4.3
Resolution: fixed
Status: newclosed
Version: 1.3.11.4.2
Note: See TracTickets for help on using tickets.