Skip to main content

Bug Tracker

Side navigation

#8380 closed bug (fixed)

Opened February 25, 2011 02:23PM UTC

Closed March 21, 2011 03:11PM UTC

Last modified March 09, 2012 08:04AM UTC

$(':text') should match <input> since `type=text` is the implied default

Reported by: mathias Owned by: john
Priority: blocker Milestone: 1.5.2
Component: selector Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:
Description

Test case: http://jsfiddle.net/mathias/CpvgM/

Currently, $(':text') only matches inputs with type=text explicitly set. It should also match <input> since type=text is the implied default in all browsers (as per the HTML spec).

Attachments (0)
Change History (18)

Changed February 25, 2011 02:25PM UTC by mathias comment:1

For the record, when this is fixed, the docs should probably be updated as well: http://api.jquery.com/text-selector/

Changed February 25, 2011 02:50PM UTC by mathias comment:2

Changed February 25, 2011 05:44PM UTC by addyosmani comment:3

cc: → snover
component: unfiledselector
priority: undecidedlow
status: newopen

Thanks. The pull request looks fairly decent - CC'ing snover for further review.

Changed February 25, 2011 06:53PM UTC by dmethvin comment:4

We talked about this on -dev today, it seems like a good idea. However we should discourage <input /> in markup since it does not match qSA for input[type=text] -- the attribute is missing, only the property is "text".

Changed February 28, 2011 03:14AM UTC by dmifedorenko@gmail.com comment:5

It is critical regression for my projects, I did not set type attribute for text input _several years_.

So now I need edit and test tons of HTML/XSL/PHP/JS templates to upgrade to jQuery 1.5.1?

Changed February 28, 2011 07:42AM UTC by mathias comment:6

@dmifedorenko: Actually, no. $(':text') should match <input> and it has always worked that way before jQuery 1.5.1 was released. The regression you’re talking about is in 1.5.1, and this patch will fix it.

Changed February 28, 2011 06:41PM UTC by dmethvin comment:7

milestone: 1.next1.5.2
priority: lowblocker

Changed February 28, 2011 06:44PM UTC by dmethvin comment:8

#8163 is a duplicate of this ticket.

Changed March 01, 2011 06:11PM UTC by gnarf comment:9

I probably introduced this bug in 1.5.1 - https://github.com/gnarf37/sizzle/commit/0048e13aa17bd805374784f7d6e6f6f0a0140fe7 -- Before that commit,

 :text 
just did "text" === elem.type -- we could potentially revert that function (not the whole commit since
 :text 
is a Sizzle only "magic" selector it can do whatever we need it to.

If you want to override this in 1.5.1 for your own regression purposes its a one line fix:

jQuery.find.selectors.filters['text'] = function(elem) { return "text" === elem.type };

http://jsfiddle.net/CpvgM/1/

Changed March 01, 2011 06:11PM UTC by snover comment:10

cc: snover

Changed March 04, 2011 04:13PM UTC by anonymous comment:11

Wouldn't this work? (to replace line 619 from https://github.com/gnarf37/sizzle/commit/0048e13aa17bd805374784f7d6e6f6f0a0140fe7)

return "text" === (elem.getAttribute( 'type' ) || "text");

As it will return the value of type, and if this is null, it will return the default: "text".

Changed March 07, 2011 04:55PM UTC by john comment:12

owner: → john
status: openassigned

Changed March 20, 2011 10:02PM UTC by dmethvin comment:13

#8565 is a duplicate of this ticket.

Changed March 21, 2011 03:11PM UTC by john comment:14

resolution: → fixed
status: assignedclosed

Landed mathias' pull request.

Changed March 21, 2011 03:35PM UTC by danheberden comment:15

keywords: → needsdocs

Changed March 21, 2011 03:35PM UTC by danheberden comment:16

Per matjas: [8:29 AM] <matjas> now that #8380 is fixed, the text on http://api.jquery.com/text-selector/ needs some tweaking

Changed March 22, 2011 03:11PM UTC by addyosmani comment:17

#8583 is a duplicate of this ticket.

Changed March 28, 2011 02:30AM UTC by kswedberg comment:18

keywords: needsdocs

updated documentation