PDA

View Full Version : [3.0rc1.1] ComboBox.getValue() wrong



MartiCode
7 May 2009, 9:30 AM
getValue() on a combobox doesn't work for text that is manually typed with the keyboard (not selected in the drop-down) :


<input type="text" id="array-states" size="20"/>

<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();

var comboFromArray = new Ext.form.ComboBox({
id: 'combo1',
xtype: 'combo',
name: 'someName',
fieldLabel: 'Categories',
store: ['a','b'],
typeAhead: true,
triggerAction: 'all',
mode: 'local',
forceSelection: false,
applyTo: 'array-states'
});
});
</script>
Typing something in the field and calling Ext.getCmp('combo1').getValue() returns an empty string. It works however if a value is selected with the mouse.

Animal
7 May 2009, 9:36 AM
That is because a value has not been selected.

Use getRawValue to access the visible input field (As opposed to the hidden input field which may be associated with a ComboBox which stores the associated valoue)

applyTo transforms an existing <select> and uses its <option>s to populate the store. IIRC, you can't have applyTo and store.

MartiCode
7 May 2009, 9:50 AM
The issue also shows up without using apply-to on an existing tag (pure javascript creation), and using a hiddenName doesn't seem to fix it. (I used apply-to here to make the example shorter)

I wouldn't mind using getRawValue() but it sounds to me that if you let the user type in something then it should also get returned with getValue(). This is especially a problem when doing automatic form submission or saving a form into a record (which seem to use getValue)

Animal
7 May 2009, 9:59 AM
It's not like that.

A ComboBox is like a <select> It associates a textual description with a value.

Please post in "Help" until you know enough to identify bugs!

MartiCode
7 May 2009, 12:06 PM
It's not like that.

A ComboBox is like a <select> It associates a textual description with a value.
Thanks. The "forceSelection" option however allows the user to put a different value than those offered.

If I understand this correctly getRawValue will actually return what the user is really seeing, but functions such as BasicForm.updateRecord() are using getValue() instead. So what is written to the record is inconsistent with what the user wanted.

I added a :
form.findField('FieldN ame').setValue(form.findField('FieldName').getRawValue());
but isn't there a better way ?

Animal
7 May 2009, 12:38 PM
There are two fields, a display and a value.

Typing in some garbage text does not select any value.

Now if you have only one field, which is both text and value, then you might have a point, but transforming a <select> has two values.

MartiCode
7 May 2009, 1:28 PM
There are two fields, a display and a value.

Typing in some garbage text does not select any value.

Now if you have only one field, which is both text and value, then you might have a point, but transforming a <select> has two values.
Thanks. My application isn't actually transforming a select but using a generated combo as a glorified textfield with a list of suggestion (search-hinting, such as a forum-search combo example). I want to save this into a record with form.updateRecord() but I guess that I'll have to update the record manually then.

Also I've noticed that while form.updateRecord() will apparently use getValue() and ignore what the user typed, form.submit() works differently and submits the text as if it was a textfield. Is there a reason for these different behaviors ? The second sounds more logical to me.

Animal
7 May 2009, 11:40 PM
It IS a text field. Look at it. It's a text field. It contains text!

Do you want a hidden field to be created to hold the value?

MartiCode
8 May 2009, 12:49 AM
It IS a text field. Look at it. It's a text field. It contains text!
Yes it is certainly a text field. But BasicForm.updateRecord() doesn't care and will not read anything that has been manually entered into it.


Do you want a hidden field to be created to hold the value?I don't need the value of the <select>, I just want the text, what the user is seeing, whether it is manually typed or choosen from the drop-down. getValue() will always return the value, for the regular field ('name' config opion) or the hidden one ('hiddenName' config option).

I understand that I can use getRawValue() for that, but once again I cannot use updateRecord() and save all form fields at once, as it seems to use getValue() internaly. Also from the docs, getRawValue() bypass validation and normalization, so this is not ideal either.

MartiCode
8 May 2009, 12:56 AM
applyTo transforms an existing <select> and uses its <option>s to populate the store. IIRC, you can't have applyTo and store.
BTW: I actually checked the Live Search combo example and it does applyTo on a <input> element and use a store at the same time.

Animal
8 May 2009, 12:56 AM
Yes, updateRecord uses getValue values.

But getValues uses values from the form's DOM structure.

So you could override updateRecord to use data from getValues.

Animal
8 May 2009, 12:57 AM
BTW: I actually checked the Live Search combo example and it does applyTo on a <input> element and use a store at the same time.

Ah right. It's transform that specifies a <select> element from which to extract the data and build a Store.

MartiCode
8 May 2009, 1:26 AM
Yes, updateRecord uses getValue values.

But getValues uses values from the form's DOM structure.

So you could override updateRecord to use data from getValues.
Thanks for the suggestion and help.

I still wish there was a config option to tell the combo that we are just interested in the text. I'd guess most people who use the "forceSelection: false" option really do intend to use the combo as a textfield (or else why let the user type something freely ?), and so would want the component to behave as such when asked for its state.