PDA

View Full Version : manipulating object of Ext.DomQuery.select()



occiso
25 Sep 2010, 6:59 AM
Hi, first of all, sorry for my english; I'm spanish.

The problem: I Want to use an object array to manipulate html Dom. I wrote this code (I use Firebug to find errors):


function LoL (){
var elementosDom = Ext.DomQuery.select("[id=formulario] input[type=text]");

console.debug('%s', elementosDom.count); // don't work
console.debug('%s', Ext.getCmp("first").getValue());
debugger;
}

Ext.onReady(function(){
var simple = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
id: "formulario",
url:'save-form.php',
frame:true,
title: 'Simple Form',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 230},
defaultType: 'textfield',

items: [{
fieldLabel: 'First Name',
id:"first",
name: 'first',
allowBlank:false
},{
fieldLabel: 'Last Name',
id:"last",
name: 'last'
},{
fieldLabel: 'Company',
id:"company",
name: 'company'
}, {
fieldLabel: 'Email',
id: 'email',
name: 'email',
vtype:'email'
}, new Ext.form.TimeField({
fieldLabel: 'Time',
name: 'time',
minValue: '8:00am',
maxValue: '6:00pm'
})
],

buttons: [{
text: 'Save',
handler: function(){
LoL();
}
},{
text: 'Cancel'
}]
});

simple.render(document.body);

});
The questions are:
How Can I Know the total number of elements for "elementosDom"?
How Can I Manipulate the properties and change it?
Definitively, How Can I access to the methods and properties of "elementosDom"?

I try with methods setValue(), getCount()... but don`t work.

If anyone know a link where explain a similar example I will become happy.

And sorry for my english again.

occiso
25 Sep 2010, 10:19 AM
HI, I found the solution to know the number of elements. But I have a dude. In Firebug I find a strange element: remove. Why?

22563

When I use a for to cross "elementosDom" I obtain an error.



function LoL (){
var item;
console.debug('elementosDom.lenght: %s', elementosDom.length);

for (item in elementosDom)
console.debug("%s", elementosDom[item].value)
}



But the elementosDom.length is correct. why ?

Animal
25 Sep 2010, 10:03 PM
Ass mentioned many times, do not use for...in on an Array!

That is for iterating Object properties, not Array elements.

Use an integer loop.

Animal
25 Sep 2010, 10:05 PM
But you do know you are selecting DOM elements (Wrapped by an Ext.Element object) don't you?

You are not selecting Ext.form.Fields. So there will be no getValue method.

occiso
26 Sep 2010, 12:37 AM
And is correct change the properties by this way instead calling a method ?



elementosDom[index].value = "new value";// correct?


Is strange for me, I always use methods.

steffenk
26 Sep 2010, 1:57 AM
form has a method called setValues, in your case

simple.getForm().setValues('first', 'other value);

your items are simply as Animal already mentioned:

for (var i=0; i < simple.items.length; i++) {