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)
Change History (6)
Changed February 11, 2009 09:43PM UTC by comment:1
Changed February 12, 2009 01:46AM UTC by 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 comment:3
component: | unfilled → core |
---|---|
priority: | major → minor |
Changed June 20, 2010 08:16PM UTC by comment:4
component: | core → attributes |
---|
Changed August 21, 2010 02:34AM UTC by comment:5
need: | Review → Commit |
---|---|
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 comment:6
milestone: | 1.3.2 → 1.4.3 |
---|---|
resolution: | → fixed |
status: | new → closed |
version: | 1.3.1 → 1.4.2 |
FYI, I'm using JSON.parse() from www.json.org to create the object.