Skip to main content

Bug Tracker

Side navigation

#13516 closed bug (invalid)

Opened February 25, 2013 04:39PM UTC

Closed March 13, 2013 08:59AM UTC

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:
Description

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.

Attachments (0)
Change History (4)

Changed February 26, 2013 01:08PM UTC by Maikel comment:1

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

Changed February 26, 2013 01:24PM UTC by anonymous comment:2

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

Changed February 26, 2013 01:59PM UTC by gibson042 comment:3

owner: → 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). "[http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#attr-input-required 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?

Changed March 13, 2013 08:59AM UTC by trac-o-bot comment:4

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!