リモート ストアを持つ ExtJS コンボ ボックス (バージョン 4.1) があります。コンボ ボックスが空になったら、コンボ ボックスをクリアしてストアする必要があります。
これを行うために、コンボ ボックスをクリアし、キー押下イベントと変更イベントを保存する関数を実装しました (以下のコードを参照)。
ただし、ユーザーがすべてを選択し (カーソルが最後にある場合は Shift+Home、カーソルが最初にある場合は Shift+End)、コンボ ボックスはそれ自体を空にすることを拒否し、バックスペース/削除を押します。このような場合、コンボ ボックスは、フォーカスを失うと、常に最後に選択された値を入力します。これは IE (クライアントが使用する) でのみ発生します。
コンボボックスがそれをしないようにする方法はありますか?
以下のコード スニペット:
// clearExistingInput function (called from combo box)
clearExistingInput: function(ths, newVal) {
if(newVal === null){
ths.store.removeAll();
ths.clearValue();
}
}
// combo box configuration
{
labelAlign : 'right',
xtype: 'combo',
store: comboStore,
filterOnLoad: true,
typeAhead: true,
hideTrigger:true,
minChars :1,
size:15,
queryDelay: 20,
queryCaching: false,
// enable paging with width that fits the paging toolbar
matchFieldWidth: false,
listConfig: {
width: 220,
height: 300,
autoHeight: true
},
maxWidth: 35,
pageSize: true,
enableKeyEvents:true,
listeners:{
'keypress':function(ths,e){
if (e.getKey() == e.DELETE || e.getKey() == e.BACKSPACE) {
this.up('formFilter').clearExistingInput(ths, ths.value);
}
},
'change': function(ths,newVal,OldVal,eOpts){
this.up('formFilter').clearExistingInput(ths, newVal);
}
}
}
// combo box store
comboStore = Ext.create('Ext.data.Store', {
pageSize: 10,
autoLoad: false,
proxy: {
type: 'ajax',
url : 'Service/data',
reader: {
type: 'json',
root: 'data'
}
},
fields: [
{name: 'data', type : 'String'}
]
});