PDA

View Full Version : getValue() not working for MixedCollection of objects



jaisol
4 Nov 2014, 9:01 AM
Hello,

I have a MixedCollection (formItems) of objects (text, combo, ...) but when I try to get their values through getValue() I have no success even some of them have values already.



for (var i = 0 ; i < formItems.getCount() ; i ++){
console.log('formItems.getAt(i):');
console.log(formItems.getAt(i));
console.log('formItems.getAt(i).getXType():');
console.log(formItems.getAt(i).getXType());
console.log('formItems.getAt(i).getValue():');
console.log(formItems.getAt(i).getValue()); // not working
console.log(Ext.getCmp(formItems.getAt(i)['id']).getValue()); // not working as well
}


As always, any help is greatly appreciated.

Thanks!

scottmartin
4 Nov 2014, 1:11 PM
It would be helpful to see your code. See if the following helps:



Ext.application({
name : 'Fiddle',

launch : function() {

var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
]
});

var form = Ext.create('Ext.form.Panel', {

height: 500,
width : 500,

renderTo: Ext.getBody(),

items: [
{
xtype: 'textfield',
name : 'orange',
label: 'Orange',
value: 'Banana'
},
{
xtype: 'checkboxfield',
name : 'tomato',
label: 'Tomato',
checked: true
},
{
xtype: 'combobox',
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
value: 'AK'

},
{
xtype: 'toolbar',
docked: 'bottom',
items: [
{
text: 'getValues',
handler: function() {
var form = Ext.ComponentQuery.query('form')[0],
values = form.getValues();

console.log(form.getValues());
}
}
]
}
]
});

}
});

jaisol
5 Nov 2014, 2:29 PM
Here is the code before the for block...



var formItems = new Ext.util.MixedCollection();
var items = [
{ 'name': 'source-type', 'ExtType': 'ComboBox' },
{ 'name': 'source-fileserver', 'ExtType': 'ComboBox' },
{ 'name': 'source-path', 'ExtType': 'Text' },
{ 'name': 'source', 'ExtType': 'Text' },
{ 'name': 'ensure', 'ExtType': 'ComboBox' },
];


Ext.each(items, function (item) {


var type = "Ext.form.field." + item['ExtType'];


if (item['name'] === 'source-type') {
newfield = Ext.create(type, {
xtype: "combo",
fieldLabel: "Source Type",
anchor: "100%",
MutuallyExclusive: "Content",
id: "field-Source-Type",
name: "source-type",
queryMode: "local",
store: [
"File Server",
"URI or absolute path"
],
typeAhead: true,
editable: false,
autoSelect: true,
selectOnFocus: true,
forceSelection: true,
ExtType: "ComboBox",
});
}


if (item['name'] === 'source-fileserver') {
newfield = Ext.create(type, {
xtype: "combo",
fieldLabel: "Source",
anchor: "100%",
MutuallyExclusive: "Content",
id: "field-source-fileserver",
name: "source-fileserver",
queryMode: "remote",
displayField: "File",
store: serverFilesStore,
typeAhead: true,
editable: false,
autoSelect: true,
selectOnFocus: true,
forceSelection: true,
ExtType: "ComboBox",
disabled: true
});
}


if (item['name'] === 'source-path') {
newfield = Ext.create(type, {
name: "source-path",
fieldLabel: "Source",
anchor: "100%",
id: "field-source-path",
xtype: "textfield",
nameField: true,
inputAttrTpl: " data-qtip='A valid URI or local\\remote absolute path or mapped drive'",
ExtType: "Text",
hidden: true
});
}


if (item['name'] === 'source') {
newfield = Ext.create(type, {
name: "source",
fieldLabel: "Source",
anchor: "100%",
id: "field-Source",
xtype: "textfield",
nameField: true,
inputAttrTpl: " data-qtip='A valid URI or local\\remote absolute path or mapped drive'",
ExtType: "Text",
hidden: true
});
}




if (item['name'] === 'ensure') {
newfield = Ext.create(type, {
xtype: "combo",
fieldLabel: "Ensure",
id: "field-ComboEnsure",
name: "ensure",
inputAttrTpl: " data-qtip='File: Ensure the file exists with the given content/source. Directory: Ensure the folder exists with the provided source. Absent: Ensure the file/folder does not exist.'",
queryMode: "local",
displayField: "ensure",
valueField: "ensure",
store: [
"directory",
"file",
"absent"
],
typeAhead: true,
editable: false,
autoSelect: true,
selectOnFocus: true,
forceSelection: true,
ExtType: "ComboBox",
});
}


formItems.add(newfield);


});



Thanks again !

carol.ext
5 Nov 2014, 3:59 PM
I don't see that any of your fields have a value. I added value: 'hello' on source and I get the value from getValue in console running on Chrome in a sencha fiddle (fiddle dot sencha dot com).


formItems.getAt(i):
constructor {name: "source", fieldLabel: "Source", anchor: "100%", id: "field-Source", xtype: "textfield"}
formItems.getAt(i).getXType():
textfield
formItems.getAt(i).getValue():
hello
hello


This is the code I threw in the launch function of default fiddle, using ExtJS 4.2.1


Ext.Msg.alert("test", "test");
var formItems = new Ext.util.MixedCollection();
var items = [{
'name': 'source-type',
'ExtType': 'ComboBox'
}, {
'name': 'source-fileserver',
'ExtType': 'ComboBox'
}, {
'name': 'source-path',
'ExtType': 'Text'
}, {
'name': 'source',
'ExtType': 'Text'
}, {
'name': 'ensure',
'ExtType': 'ComboBox'
}];


Ext.each(items, function(item) {


var type = "Ext.form.field." + item['ExtType'];


if (item['name'] === 'source-type') {
newfield = Ext.create(type, {
xtype: "combo",
fieldLabel: "Source Type",
anchor: "100%",
MutuallyExclusive: "Content",
id: "field-Source-Type",
name: "source-type",
queryMode: "local",
store: [
"File Server",
"URI or absolute path"
],
typeAhead: true,
editable: false,
autoSelect: true,
selectOnFocus: true,
forceSelection: true,
ExtType: "ComboBox"
});
}

debugger;

if (item['name'] === 'source-fileserver') {
newfield = Ext.create(type, {
xtype: "combo",
fieldLabel: "Source",
anchor: "100%",
MutuallyExclusive: "Content",
id: "field-source-fileserver",
name: "source-fileserver",
queryMode: "remote",
displayField: "File",
store: [{
"File": "File Server"
}, {
"File": "URI or absolute path"
}],
typeAhead: true,
editable: false,
autoSelect: true,
selectOnFocus: true,
forceSelection: true,
ExtType: "ComboBox",
disabled: true
});
}


if (item['name'] === 'source-path') {
newfield = Ext.create(type, {
name: "source-path",
fieldLabel: "Source",
anchor: "100%",
id: "field-source-path",
xtype: "textfield",
nameField: true,
inputAttrTpl: " data-qtip='A valid URI or local\\remote absolute path or mapped drive'",
ExtType: "Text",
hidden: true
});
}


if (item['name'] === 'source') {
newfield = Ext.create(type, {
name: "source",
fieldLabel: "Source",
anchor: "100%",
id: "field-Source",
xtype: "textfield",
nameField: true,
inputAttrTpl: " data-qtip='A valid URI or local\\remote absolute path or mapped drive'",
ExtType: "Text",
hidden: true,
value: 'hello'
});
}




if (item['name'] === 'ensure') {
newfield = Ext.create(type, {
xtype: "combo",
fieldLabel: "Ensure",
id: "field-ComboEnsure",
name: "ensure",
inputAttrTpl: " data-qtip='File: Ensure the file exists with the given content/source. Directory: Ensure the folder exists with the provided source. Absent: Ensure the file/folder does not exist.'",
queryMode: "local",
displayField: "ensure",
valueField: "ensure",
store: [
"directory",
"file",
"absent"
],
typeAhead: true,
editable: false,
autoSelect: true,
selectOnFocus: true,
forceSelection: true,
ExtType: "ComboBox",
});
}


formItems.add(newfield);


});
Ext.Msg.alert("test3", "test3");
for (var i = 0; i < formItems.getCount(); i++) {
console.log('formItems.getAt(i):');
console.log(formItems.getAt(i));
console.log('formItems.getAt(i).getXType():');
console.log(formItems.getAt(i).getXType());
console.log('formItems.getAt(i).getValue():');
console.log(formItems.getAt(i).getValue()); // not working
console.log(Ext.getCmp(formItems.getAt(i)['id']).getValue()); // not working as well
}