Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS - How to get component item value

I have a component as follow :

{
    xtype: 'fieldcontainer',
    layout: 'hbox',
    id: 'article-level-container',
    defaultType: 'textfield',
    fieldDefaults: {
        labelAlign: 'top'
    },
    items: [{
        fieldLabel: 'LEVEL',
        name: 'artLevel',
        inputWidth: 216,
        margins: '0 5 5 0',
        allowBlank: false,
        fieldStyle: 'text-align: right; font-size: 13pt; background-color: #EAFFCC;'
    }, {
        fieldLabel: 'VALUE',
        name: 'artValue',
        inputWidth: 216,
        allowBlank: false,
        blankText: 'zorunlu alan, boş bırakılamaz',
        fieldStyle: 'text-align: right; font-size: 13pt; background-color: #EAFFCC;',
        listeners: {
            change: function(textfield, newValue, oldValue) {
                if (oldValue == 'undefined' || newValue == '') {
                    Ext.getCmp('btnArticleSave').disable();
                } else {
                    Ext.getCmp('btnArticleSave').enable();
                }
            }
        }
    }]
} 

I want to get second item fieldLabel value ( in this case VALUE ).

  • How can I get this field value outside the onReady function?
  • How can I change this field label with new value ( I want to change fieldlabel with selected combobox value )

UPDATE I tried the following :

var artField = Ext.ComponentQuery.query('#articleValueField');
console.log(artField);

Console Output

like image 468
Oğuz Çelikdemir Avatar asked Jul 16 '13 07:07

Oğuz Çelikdemir


People also ask

What is the benefit of using Itemid in Extjs?

When you use an id for a component, there must be a single instance of this component, If you create another instance that has the same id, you will have problems as the DOM is confused. when you use itemId, it should be unique only within the component's immediate container.

What is the correct syntax for creating a component in Extjs?

Using xtype xtype is an easy way to create Components without using the full class name. This is especially useful when creating a Ext. Container that contains child Components. An xtype is simply a shorthand way of specifying a Component - for example you can use xtype: 'panel' instead of typing out Ext.

What is the benefit of using Itemid?

The itemid global attribute provides microdata in the form of a unique, global identifier of an item. An itemid attribute can only be specified for an element that has both itemscope and itemtype attributes.


2 Answers

A few ways but common is to use Ext.ComponentQuery:

Give your field an itemId in its config e.g. itemId: 'theField':

 var field= Ext.ComponentQuery.query('#theField')[0];
 field.setFieldLabel(valueFromCombo);

Add an on change listener to your combo, you can use up and down (which are also component queries)

listeners: {
  change: function(combo) {
    var form = combo.up('#form');
    var field = form.down('#theField');
    field.setFieldLabel(lookupValueFromCombo);
  }
}

Remember any config settings in ext js will get a setter and getter, thus fieldLabel has getFieldLabel() & setFieldLabel(s) methods.

edit above is only with ext js 4.1+ with ext js 4.0+ you can do:

field.labelEl.update('New Label');
like image 110
jenson-button-event Avatar answered Sep 20 '22 15:09

jenson-button-event


to get the combobox selected item outside the combo listener

yourComboboxName.on('change', function (combo, record, index) {

            alert(record);  // to get the selected item

            console.log(record);  // to get the selected item

        });
like image 44
Ahmed MEZRI Avatar answered Sep 22 '22 15:09

Ahmed MEZRI