1
votes

Just a simple question, is it possible to call an ExtJS function to be able to set default value when we are defining a component like below? Because, when I tried below, the function doesn't assign the value.

{
  xtype: 'textfield',
  fieldLabel: 'DNR TYPE',
  name: 'DNR_TYPE,
  value: Ext.getCmp('dnr-type').getRawValue() 
  // here is the function that I want to call and assign the value
}

EDIT :

Dear friends, I found the problem which is related with form render. When application startup, the form initialized with default values. Therefore, the field value returning empty. When user select a record from the combobox, I should assign that value to related textfield.

Now, is there any method to refresh/reload form again when user select a record from the form?

2
Why not just try it and see if it works? - NDM
I tried, it doesn't work! I wanted to know that am I doing something wrong. - Oğuz Çelikdemir
You need to put together a working test case. You're talking about code that isn't referenced anywhere in what you posted. - Evan Trimboli
@EvanTrimboli I found the problem. The form panel rendered before users select a record from the combobox. Therefore, the value didn't assign the field. Are there any method the refresh/reload the form? - Oğuz Çelikdemir

2 Answers

0
votes

as long as Ext.getCmp('dnr-type').getRawValue() returns a string its possible...

0
votes

One solution that you can try is :

{
  xtype: 'textfield',
  fieldLabel: 'DNR TYPE',
  name: 'DNR_TYPE,
  listeners: {
    beforerender: function() {
       this.setValue(Ext.getCmp('dnr-type').getRawValue());
    }
  }
}

If Ext.getCmp('dnr-type').getRawValue() returns value, it will be assigned to textfield, otherwise if it is blank string then textfield will contain blank value and you wouldn't see value in textfield.

EDIT:

When user select a record from the combobox, I should assign that value to related textfield.

----> you can change value of textfield on select event of combo like :

{
    xtype: 'combo'
    displayField: 'foo',
    valueField: 'bar',
    lsiteners: {
       select: function( combo, records) {
          var rec = records[0]; // records will contain selected records(1 or more)
          var textField = // get textfield using Ext.getCmp()
          textField.setValue(rec.get('modelName'));
       }
    }
}

Now, is there any method to refresh/reload form again when user select a record from the form?

----> I am not clear with this. May be I can help you with this if you tell me the scenario