PDA

View Full Version : Ext.DomQuery for searching elements with attributes



satish.vicky
18 Feb 2011, 12:44 AM
HI

Iam facing a issue with writing a XPAth for finding elements with userdefined attributes.

I Have some Xtype's as follows defined with in formpanel

{
xtype: 'radio',
value: 'And',
id :'lab6',
foo:'1',
x: 360,
y: 30,
boxLabel: 'or'
},
{
xtype: 'textfield',
value: '12',
id :'lab4',
Param:'2',
x: 140,
y: 90
}

and to search those elements iam using the following query

Ext.DomQuery.select("*[@foo='1']")

But this particular query is not returning any nodes.

Can some one tell me what is the mistake iam doing.

steffenk
18 Feb 2011, 3:58 AM
you can't search for an attribute in DOM that isn't rendered.

satish.vicky
18 Feb 2011, 8:52 AM
i have rendered the form even after rendering iam not able to search for attribute.Please suggest.

Condor
18 Feb 2011, 9:21 AM
'foo' is a component property and not an element attribute, so you won't find it!

What exactly do you need this for? It doesn't look like the right approach.

satish.vicky
18 Feb 2011, 9:31 AM
Hi condor

I want all the components defined with in a form which has got a property or attribute 'foo' whose value is 1.

Condor
18 Feb 2011, 9:43 AM
var components = [];
formPanel.cascade(function(c){
if (c.foo == 1) {
components.push(c);
}
});

satish.vicky
18 Feb 2011, 9:50 AM
Thanks for the quick reply condor.

Might be my requirement is something different.something like this.

<input type="text" customattribute="123" id="w123" ></input>
<input type="text" customattribute="143" id="w124" ></input>

The above mentioned are normal html elements.Now i want to create a formpanel in EXTJS which should contain two EXTJS textfields with custom attriabutes(customattribute) and on that form i want to do a xpath query to find those elements.

Condor
19 Feb 2011, 8:27 AM
OK, but adding new properties doesn't create extra attributes.

For that you will have to specify an 'autoCreate' config option, e.g.

autoCreate: Ext.apply({customattribute: '123'}, Ext.form.TextField.prototype.defaultAutoCreate)