В комбо есть волшебный метод, называемый assertValue
, который часто вызывает некоторые вопросы:
assertValue: function() {
var me = this,
value = me.getRawValue(),
rec, currentValue;
if (me.forceSelection) {
if (me.multiSelect) {
// For multiselect, check that the current displayed value matches the current
// selection, if it does not then revert to the most recent selection.
if (value !== me.getDisplayValue()) {
me.setValue(me.lastSelection);
}
} else {
// For single-select, match the displayed value to a record and select it,
// if it does not match a record then revert to the most recent selection.
rec = me.findRecordByDisplay(value);
if (rec) {
currentValue = me.value;
// Prevent an issue where we have duplicate display values with
// different underlying values.
if (!me.findRecordByValue(currentValue)) {
me.select(rec, true);
}
} else {
me.setValue(me.lastSelection);
}
}
}
me.collapse();
}
В основном, когда вы не используете multiSelect
то lastSelection
используется всегда, когда вы пытаетесь установленное значение, которое невозможно найти в магазине. Обычно я добавляю фиктивную запись для хранения, что соответствует пустому значению. Проблема вернется, если вам нужно установить allowBlank
в значение false.
В качестве альтернативы, чтобы добавить фиктивную запись можно переопределить assertValue
метод, как это:
assertValue: function() {
var me = this,
value = me.getRawValue();
if (me.forceSelection && me.allowBlank && Ext.isEmpty(value)) {
me.setValue(value);
me.collapse();
return;
}
this.callParent(arguments);
}