Bug Tracker

Opened 10 years ago

Closed 10 years ago

#13516 closed bug (invalid)

Attribute-filter combined with :visible gives no results

Reported by: anonymous Owned by: anonymous
Priority: undecided Milestone: None
Component: unfiled Version: git
Keywords: Cc:
Blocked by: Blocking:


To validate a form, I used to loop through all visible input-fields having the attribute 'Required' set to 'true': $("input[Required='true']:visible")

After upgrading from jQuery 1.6.2 to 1.9.1, this stopped working. The code above doesn't return any results. When I change it to use a filter, I get the correct results again: $("input[Required='true']").filter(":visible")

Filtering on the type-attribute works fine, so I'm unsure what is causing this problem exactly.

Change History (4)

comment:1 Changed 10 years ago by Maikel

I created a jsFiddle-example: http://jsfiddle.net/9NHf2/1/

comment:2 Changed 10 years ago by anonymous

I updated the example: http://jsfiddle.net/9NHf2/3

comment:3 Changed 10 years ago by gibson042

Owner: set to anonymous
Status: newpending

This is an artifact of jQuery-specific attribute handling, as can be seen at http://jsfiddle.net/9NHf2/4/.

When testing HTML attributes, we check to see if the lowercased name matches a list of known booleans (attributes whose values are normalized to their names whenever they exist). "required" is in the list, so the value gets normalized to "required", which obviously doesn't match "true". The input[Required='true'] filter doesn't have contain any jQuery extensions, and so uses the browser's native querySelectorAll when available—it also returns zero matches if you run it in IE7, for instance. In other words, this behavior is by design, but performance optimizations mean we don't catch all cases.

The good news is that you appear to be using attribute "Required" for the same purposes as boolean attribute "required", so I recommend that you switch to the latter if possible. Your other alternative would be to pick a non-boolean name and keep the "true" values.

Do either of these work for you?

comment:4 Changed 10 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Note: See TracTickets for help on using tickets.