Skip to main content

Bug Tracker

Side navigation

#4130 closed bug (fixed)

Opened February 11, 2009 09:40PM UTC

Closed September 24, 2010 09:58PM UTC

Last modified March 14, 2012 12:11PM UTC

.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 (0.6 KB) - added by ptran123 February 11, 2009 09:40PM UTC.
Change History (6)

Changed February 11, 2009 09:43PM UTC by ptran123 comment:1

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

Changed February 12, 2009 01:46AM UTC by dmethvin comment:2

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 || "")
.

Changed August 09, 2009 01:05AM UTC by dmethvin comment:3

component: unfilledcore
priority: majorminor

Changed June 20, 2010 08:16PM UTC by dmethvin comment:4

component: coreattributes

Changed August 21, 2010 02:34AM UTC by dmethvin comment:5

need: ReviewCommit
owner: → 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

Changed September 24, 2010 09:58PM UTC by john comment:6

milestone: 1.3.21.4.3
resolution: → fixed
status: newclosed
version: 1.3.11.4.2