ExtJS ComboBox(使用queryMode remote和forceSelection true配置)自动清除输入字段

时间:2015-09-23 13:20:27

标签: javascript extjs combobox

使用queryMode配置的组件Ext.form.field.ComboBox" remote"和forceSelection true在搜索商店后自动清除其输入字段。

{
    xtype: 'combobox',

    fieldLabel: 'State',

    forceSelection: true,
    queryMode: 'remote',
    displayField: 'name',
    valueField: 'id',
    typeAhead: true,
    minChars: 0,

    store: {
        model: 'ComboTest.State',
        pageSize: 100,

        proxy: {
            type: 'ajax',
            url: 'states.js',
            reader: {
                type: 'json',
            }
        }
    },

    allowBlank: false

}

你可以尝试这个小提琴:https://fiddle.sencha.com/#fiddle/uaq

插入,例如" w",组合框选择"华盛顿",然后继续插入" y" (例如,你想要"怀俄明"),此时一切都被清除。

我做错了什么还是错误?

1 个答案:

答案 0 :(得分:1)

这是一个常见的错误,在extjs 5中,我猜这个错误存在于extjs 6中。

您可以覆盖组合框行为:

Ext.define('overrides.form.ComboBox', {
    override: 'Ext.form.ComboBox',
    onLoad: function (store, records, success) {
        var me = this,
        needsValueUpdating = !me.valueCollection.byValue.get(me.value);
        if (success && needsValueUpdating && !(store.lastOptions && 'rawQuery' in store.lastOptions)) {
            me.setValueOnData();
        }
    },
    beforeBlur: function () {
        var me = this;
        if (me.getRawValue().length === 0 || (me.getValue() == null && this.forceSelection)) {
            me.reset();
            me.lastSelection = [];
        }
        me.callParent(arguments);
    }
});
相关问题