1

I'm using ExtJs 4 and in my Web application I have a combo box. Previously I used to set the default value of the combo box using emptyText. It works just fine. But, is there any alternative way of setting the default value for the same?

I looked into different questions here on SO and tried the following -

Ext.getCmp('myComboBoxID').setValue("myValue");

However, this doesn't seem to be working. I also tried the simple value attribute to no avail. How can I the set the default value other than using emptyText?

Also, when the value is set using emptyText, it is displayed in gray color (which is poorly vsible), I was wondering if one can work with the opacity of the ExtJs select box?

Update: I used Ext.getCmp('myComboBoxID').setRawValue("myValue"); to set the value & it worked. What is the difference between setValue() & setRawValue()?

1
  • ComboBox setValue override the method in Ext.form.field.Field' which fires the change` event. setRawValue does not fire an event. I have not verified but I believe setRawValue does not verify the value is in the store. Commented Jan 28, 2014 at 8:29

3 Answers 3

2

You need to supply the id to getCmp method. Try the following.

Ext.getCmp('#myComboBoxID').setValue("myValue");

Sign up to request clarification or add additional context in comments.

Comments

1

I used Ext.getCmp('myComboBoxID').setRawValue("myValue"); to set the value & it worked.

Comments

0

The store needs to be loaded before you call setValue and you use the id of the record you want to select. There is a load event you can listen for if the values are loaded from the server. emptyText is not intended for default values, but to help the user understand what should be done with the field (eg "Select a state" from a list of states)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.