Bug Tracker

Modify

Ticket #7423 (closed bug: worksforme)

Opened 3 years ago

Last modified 2 years ago

`val` fails to return numeric elem.value

Reported by: vostrel Owned by:
Priority: high Milestone: 1.5
Component: attributes Version: 1.4.3
Keywords: Cc:
Blocking: Blocked by:

Description

When non-string value is assigned to element by:

.val(3.5);

and then retrieving the value back using:

.val();

I'm getting (in Chrome 7.0):

TypeError: Object 3.5 has no method 'replace'

pointing me to line 1589 in the latest 1.4.3. In there:

return (elem.value || "").replace(rreturn, "");

I'm not really sure if this actually is a bug or a feature. Either way my tests uncovered this issue.

I think adding an empty string to the elem.value would make it a string and while not hurting existing strings. But I may as well be missing the big picture here.

return (elem.value + "" || "").replace(rreturn, "");

Or are values required to be just strings?

Thanks very much for clarification

Change History

comment:1 Changed 3 years ago by vostrel

Correction: when the value is assigned using val it kinda works - assigned numeric value is returned as a string. But hey, who cares, string to number conversion is cheap. It fails on assigning the numeric value directly to the DOM node using value property.

comment:2 Changed 3 years ago by rwaldron

  • Priority changed from undecided to high
  • Resolution set to worksforme
  • Status changed from new to closed
  • Component changed from unfiled to attributes

I cannot reproduce this issue with 1.4.4rc2

 http://jsfiddle.net/rwaldron/z2R4C/3/

comment:3 Changed 3 years ago by vostrel

OK. Thanks

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.