Looks like we can't reproduce the issue or there's a problem in the test case provided.
-
Combobox forceSelection with bind problem
Hi all,
here is a fiddle with the problem. Try to make some change in combo, for example remove the last letter. As a result the combo box's value clears. So when combo is configured with forceSelection: true and value is binded, trying to make changes in combo clears value.
-
Ok, but you've said it must have a selection. So when you start typing and nothing matches, the value of the combo becomes null. Sounds like you want to bind to the selection.
-
I just want it works proper, in the way it works with normal(not binded value).
The problem is, that setting value is placed in getValue method of the combo:
Code:
getValue: function() {
// If the user has not changed the raw field value since a value was selected from the list,
// then return the structured value from the selection. If the raw field value is different
// than what would be displayed due to selection, return that raw value.
var me = this,
store = me.getStore(),
picker = me.picker,
rawValue = me.getRawValue(), //current value of text field
value = me.value; //stored value from last selection or setValue() call
// getValue may be called from initValue before a valid store is bound - may still be the default empty one.
// Also, may be called before the store has been loaded.
// In these cases, just return the value.
// In other cases, check that the rawValue matches the selected records.
if (!store.isEmptyStore && me.getDisplayValue() !== rawValue) {
me.displayTplData = undefined;
if (picker) {
// We do not need to hear about this clearing out of the value collection,
// so suspend events.
me.valueCollection.suspendEvents();
picker.getSelectionModel().deselectAll();
me.valueCollection.resumeEvents();
me.lastSelection = null;
}
// If the raw input value gets out of sync in a multiple ComboBox, then we have to give up.
// Multiple is not designed for typing *and* displaying the comma separated result of selection.
// Same in the case of forceSelection.
// Unless the store is not yet loaded, which case will be handled in onLoad
if (store.isLoaded() && (me.multiSelect || me.forceSelection)) {
value = me.value = undefined;
} else {
value = me.value = rawValue;
}
}
// Return null if value is undefined/null, not falsy.
me.value = value == null ? null : value;
return me.value;
},
And when you type into combo the setValue doesn't trigger, but when you bind a value and change the value in combo by typing, the binding triggers setValue and rawValue clears with it.
The real case that annoying is: after fiddle is rendered, select all text in combo and try to type new value.
-
evant, re-read you comment. Sorry, didn't get your solution from the first time. It is really workaround, while on initial load I have only id and provide to backend I should only id. I should every time find a record to bind and convert it before sending. Actually binding works properly, but the combo behaves improper in that case. At least from my point of view there should be no difference between using binded and normal value.I hope it will be fixed. Thanks.
-
I have overridden the setValue of combo with:
Code:
setValue: function (value) {
var me = this;
if (value != null) {
return me.doSetValue(value);
} else {
if (!me.getStore().isEmptyStore && me.getDisplayValue() !== me.rawValue && me.getDisplayValue() != me.rawValue &&
me.getStore().isLoaded() && (me.multiSelect || me.forceSelection)) {
me.value = null;
} else {
me.suspendEvent('select');
me.valueCollection.beginUpdate();
me.pickerSelectionModel.deselectAll();
me.valueCollection.endUpdate();
me.lastSelectedRecords = null;
me.resumeEvent('select');
}
}
}
Could you please advise, what could be a side effects of this override?
Thanks in advance.
-
Eventually I used selection facepalm.png
-
Something similar was here https://www.sencha.com/forum/showthread.php?291421 and was interpreted as a bug. Marked as fixed but seems not completely.
-
Binding doesn't provide any extra "magic" in terms of how components work. If you have no active selection then the value becomes null, that's how forceSelection works for combobox.
-
Remove bind from the combo and use normal value and it will work proper, while rawValue will not replaced with null, so the magic happens. As I said the bind triggers setValue what isn't happening during normal value use. It is definitive a bug that you reject to accept. You have placed a setter logic into a getter function and now there is a problem.
-
I have modified a fiddle to get a difference.