1

有组合框和相关的商店,如果商店中没有用户输入的值的条目,则重置一切都是正确的,但是如果用户输入的值在商店中,但他会很快做到这一点,而有一个令人不快的功能存储还没有来得及加载输入值将被重置。

如果用户没有等到商店加载(如果输入的值在商店中),当他移动到另一个表单字段时如何不重置用户输入的值

var bik = new Ext.form.ComboBox({
        store: storeBik,
        displayField: 'BANK_NAME',
        fieldLabel: 'БИК',
        name: 'BIK',
        hiddenName: 'BIK',
        valueField:'BIK',
        typeAhead: true,
        forceSelection:true,
        selectOnFocus:true,
        triggerAction: 'all',
        minChars : 1,
        mode: 'remote'
        resizable : true,
        validator : validBik,
        tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item"><b>{BIK} </b> {BANK}</div></tpl>')

    });
4

1 回答 1

1

发生这种情况的原因是因为您打开了forceSelection. 模糊后ComboBox试图在存储中为键入的值找到合适的记录。如果这样的记录不存在,它会重置值。

我可以想到2个解决方案:

  • 关掉forceSelection
  • 延长ComboBox

我看到您附加了validBik验证器。如果您可以在客户端验证价值,然后关闭forceSelection,您将拥有所需的一切。另一方面,如果您确实需要存储数据以从中选择值,那么您应该扩展ComboBox.

以下是ComboBox在请求结束之前保持价值的修改。它并不完美,但也许会对您有所帮助:

var bik = new Ext.form.ComboBox({
    [...],

    // Check if query is queued or in progress
    isLoading: function() {
        return this.isStoreLoading || // check if store is making ajax request
            this.isQueryPending; // check if there is any query pending
    },

    // This is responsible for finding matching record in store
    assertValue: function() {
        if (this.isLoading()) {
            this.assertionRequired = true;
            return;
        }

        Ext.form.ComboBox.prototype.assertValue.apply(this, arguments);
    },

    // this is private method; you can equally write 'beforeload' event handler for store
    onBeforeLoad: function(){
        this.isQueryPending = false;
        this.isStoreLoading = true;

        Ext.form.ComboBox.prototype.onBeforeLoad.apply(this, arguments);
    },

    // catch moment when query is added to queue
    onKeyUp: function(e){
        var k = e.getKey();
        if(this.editable !== false && this.readOnly !== true && (k == e.BACKSPACE || !e.isSpecialKey())){
            this.isQueryPending = true;
        }

        Ext.form.ComboBox.prototype.onKeyUp.apply(this, arguments);
    },

    // this is private method; you can equally write 'load' event handler for store
    onLoad: function() {
        Ext.form.ComboBox.prototype.onLoad.apply(this, arguments);

        this.isQueryPending = false;
        this.isStoreLoading = false;
        if (this.assertionRequired === true) {
            delete this.assertionRequired;
            this.assertValue();
        }
    }
});
于 2013-10-16T10:06:50.317 回答