2016-11-23 97 views

回答

0

出現問題的原因組合強制選擇,即使用戶沒有實際選擇其他值的錯誤。

有幾種方法可以解決此問題。

  1. 使用選擇收聽,而不forceSelection
  2. 使用更改聽者forceSelection

兩種方式,用戶將不得不選擇從組合列表(這是可能的,爲什麼你的項目首先使用forceSelection配置)。

Test the workaround in fiddle

0

我在extjs 6.5.2 modern同樣的問題。我正在使用和queryMode: 'remote',forceSelection: true,自定義itemTpl,我在使用select事件選擇一個項目。 @ Jzf的解決方案沒有爲我工作(我也使用了change事件),所以我不得不暫停focusleaveselect事件並恢復它在focusenter

這不是一個非常乾淨的解決方法,但它爲我的情況做了工作。 以下是我的combobox的完整代碼:

  { 
       xtype: 'combobox', 
       store: Ext.create('demo.store.search.SearchComboStore'), 
       valueField: 'id', 
       displayField: 'name', 
       queryMode: 'remote', 
       queryParam: 'name', 
       triggerAction: 'all', 
       allQuery: '', 
       minChars: 1, 
       forceSelection: true, 
       matchFieldWidth: false, 
       //[modern] added floated picker config here in order to set the minWidth property for the floated picker 
       floatedPicker: { 
        minWidth: (Ext.getBody().getWidth()/2) 
       }, 
       itemTpl: 
        '<div class="ucResultsTable" style="width:' + (Ext.getBody().getWidth()/2) + 'px">' + 
         '<div class="ucResultsTableCell" style="width:15%"><b>{value1}</b></div>' + 
         '<div class="ucResultsTableCell" style="width:15%">{value2}</div>' + 
         '<div class="ucResultsTableCell" style="width:15%">{value3}</div>' + 
         '<div class="ucResultsTableCell" style="width:15%">{value4}</div>' + 
         '<div class="ucResultsTableCell" style="width:15%">{value5}</div>' + 
        '</div>', 
       listeners: { 
        select: function (comboBox, records, eOpts) { 
         var container = comboBox.up('app-container-panel'); 
         container.fireEvent('selectComboItem', container, records.data); 
        }, 
        //<Workaround> 
        //blur/focusleave is firing select event 
        //and changes the record selection 
        focusleave: function (comboBox) { 
         comboBox.suspendEvent('select'); 
        }, 
        focusenter: function (comboBox) { 
         comboBox.resumeEvent('select'); 
        } 
        //</Workaround> 
       } 
      }