Results 1 to 4 of 4

Thread: getValue() not working for MixedCollection of objects

  1. #1
    Sencha User
    Join Date
    Apr 2013
    Posts
    4

    Default getValue() not working for MixedCollection of objects

    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.

    Code:
    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!

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,409
    Answers
    716

    Default

    It would be helpful to see your code. See if the following helps:

    Code:
    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());
                                }
                            }
                        ]
                    }
                ]
            });
    
        }
    });

  3. #3
    Sencha User
    Join Date
    Apr 2013
    Posts
    4

    Default

    Here is the code before the for block...

    Code:
    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 !

  4. #4
    Sencha User carol.ext's Avatar
    Join Date
    Jun 2007
    Location
    Littleton, Colorado, USA
    Posts
    707
    Answers
    25

    Default

    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).

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

    Code:
           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
          }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •