Opened 12 years ago

Closed 10 years ago

#5179 closed defect (fixed)

dojo.query :selected does not work

Reported by: guest Owned by: alex
Priority: high Milestone: 1.4
Component: Query Version: 1.3.2
Keywords: query checked Cc:
Blocked By: Blocking:

Description (last modified by alex)

The following code returns EVERY input element within a form not just the input elements that are checked (which would make them type=checkbox too)

Accourding to the Dojo documentation HERE it is suppose to return only the Checked elements.

var form = dojo.byId( 'formID' );

var results = dojo.query( "input:checked", form );

I also tried this:

var form = dojo.byId( 'formID' );

var results = dojo.query( "input[type=checkbox][checked]", form );

But it did not return any elements.

Attachments (1)

queryPseudoCheckedTest_5179.patch (1019 bytes) - added by Sam Foster 10 years ago.
[CLA] [PATCH] Adds failing option:checked test to tests/_base/query.html

Download all attachments as: .zip

Change History (14)

comment:1 Changed 12 years ago by guest

The title is a little confusing -- I meant to mention that both the :selected and the :checked are broken in this regard.

comment:2 Changed 12 years ago by guest

I found the following comment in dojo.query -- I believe we should make this information known in the Documentation on Query so others like me don't waste their time trying to figure out why they don't work.

		//		Unsupported Selectors:
		//		--------------------
		//
		//		While dojo.query handles many CSS3 selectors, some fall outside of
		//		what's resaonable for a programmatic node querying engine to
		//		handle. Currently unsupported selectors include:
		//		
		//			* namespace-differentiated selectors of any form
		//			* "~", the immediately preceeded-by sibling selector
		//			* "+", the preceeded-by sibling selector
		//			* all "::" pseduo-element selectors
		//			* certain pseduo-selectors which don't get a lot of day-to-day use:
		//				* :root, :lang(), :target, :focus
		//			* all visual and state selectors:
		//				* :root, :active, :hover, :visisted, :link, :enabled, :disabled, :checked
		//			* :*-of-type pseudo selectors

comment:3 Changed 12 years ago by Adam Peller

Owner: changed from anonymous to alex

comment:4 Changed 12 years ago by dylan

Milestone: 1.1

comment:5 Changed 12 years ago by bill

Milestone: 1.11.2

Move all milestone 1.1 tickets to 1.2, except for reopened tickets and tickets opened after 1.1RC1 was released.

comment:6 Changed 11 years ago by alex

Resolution: fixed
Status: newclosed

(In [14408]) adding support for the ":checked" pseudo selector. Fixes #5179. !strict

comment:7 Changed 11 years ago by alex

Description: modified (diff)

note that the CSS 3 working draft has removed the ":selected" pseudo-class in favor of ":checked", which we now implement

comment:8 Changed 10 years ago by bill

Component: GeneralQuery

Changed 10 years ago by Sam Foster

[CLA] [PATCH] Adds failing option:checked test to tests/_base/query.html

comment:9 Changed 10 years ago by Sam Foster

Milestone: 1.2tbd
Resolution: fixed
Status: closedreopened
Version: 1.01.3.2

I've attached a patch for the query test file that adds a test for :checked pseudo as applied to a select option. This passes for me in FF3.5, but fails in IE7 and Safari 4.0

I tried amending the function in query.js, like so:

"checked": function(name, condition){
	return function(elem){
		return !!d.attr(elem, d.hasAttr(elem, "checked") ? "checked" : "selected");
	}
},

but while this fixed IE, it seems to still fail in Safari? Not sure if safari is using this branch, or what's going on.

comment:10 Changed 10 years ago by Sam Foster

(In [20574]) Added test for :checked psuedo as applied to <option selected> (per CSS3 spec). Refs #5179

comment:11 Changed 10 years ago by bill

Milestone: tbd1.4

Failing on IE6 too (unsurprisingly). Should either fix for 1.4 or punt this ticket and comment out the test until it's fixed.

comment:12 Changed 10 years ago by Sam Foster

This seems to be a deficiency in QSA for webkit, and for IE8, so it will need some handling on that side. Probably the easiest is to add :checked to the list of indexOf checks which set useQSA:

			(query.indexOf(":contains") == -1) && query.indexOf(":checked") == -1)
...

then, the above change to test hasAttr("checked") and then hasAttr("selected") works in all cases.

The inline docs are a little self-contradictory on this. On one hand they say state selector are not supported, but then go on to say :checked is. If that's the case, this should be fixed. I'll check in the change if I get the nod, the unit test is already in place.

comment:13 Changed 10 years ago by James Burke

Resolution: fixed
Status: reopenedclosed

(In [20843]) Fixes #5179, thanks to sfoster for doing the work figuring it out. Fixes :checked for option elements \!strict

Note: See TracTickets for help on using tickets.