#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)
Change History (7)
Changed 14 years ago by
Attachment: | HTMLPage.htm added |
---|
comment:1 Changed 14 years ago by
comment:2 Changed 14 years ago by
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 14 years ago by
Component: | unfilled → core |
---|---|
Priority: | major → minor |
comment:4 Changed 13 years ago by
Component: | core → attributes |
---|
comment:5 Changed 13 years ago by
need: | Review → 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 13 years ago by
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.