Bug Tracker

Modify

Ticket #2076 (closed bug: fixed)

Opened 6 years ago

Last modified 5 years ago

$.trim Error: (text || "").replace is not a function

Reported by: apaella@… Owned by:
Priority: major Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: Cc:
Blocking: Blocked by:

Description

call $.trim($('#id').val()) over a #id empty input throws an Error: (text
"").replace is not a function

$('#id').val() == []

and ([]
"") is not a string...

Attachments

index.html Download (511 bytes) - added by apaella@… 6 years ago.
a live example

Change History

Changed 6 years ago by apaella@…

a live example

comment:1 Changed 6 years ago by davidserduke

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in [4220].

Actually $.trim hasn't changed since 1.2.1 (and probably earlier). This problem was with val() and your test case. The test case doesn't wait till the document is ready so $("#foo").length == 0 as you noted. If you put the code inside

$(document).ready(function(){
    /* code here */
});

it will work fine.

But as it turned out this was a good test since val was incorrectly returning an empty array instead of undefined as it used to. One other thing, just for completeness, is your example has an input with type="input" but to my knowledge there is no such input type. Firefox converts that to type="text". I'm not sure what other browsers would do.

comment:2 Changed 6 years ago by apaella@…

ops, sorry fom my double mistake :D

thanks for the patch.

great job!

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.