I'm working with an older version of ExtJS (4.2) and I have added a combobox to one of edit forms in my application.
The ComboBox looks like this:
Ext.define('RgiApp.view.ImjestoTipObjektaCombo2', {
extend: 'Ext.form.field.ComboBox',
alias: 'widget.imjestoTipObjektaCombo2',
requires: 'RgiApp.store.ImjestoTipObjektaStore2',
fieldLabel: 'Vrsta obilježja II',
name: 'vrstaobiljezjaid2',
displayField: 'name',
valueField: 'id',
matchFieldWidth: true,
queryMode: 'local',
forceSelection: false,
typeAhead: true,
minChars: 2,
//listWidth: 200,
//width: 200,
//minListWidth : 200,
store: 'RgiApp.store.ImjestoTipObjektaStore2'
});
The combobox is populated with records from database and it works fine, but when I edit a record that contains NULL value in this filed, the value sets to zero (picture below).
I want combobox to be empty if there is a NULL value, so It submits NULL if left so. This way, I have to manualy delete zero before submitting the form.
EDIT:
I added emptyText
property to my combobox and now the form contains that text if I create new record, but it is still zero when I edit. These values are NULL in database.
答案 0 :(得分:1)
尝试将emptyText属性添加到组合框定义。 Ext.form.field.Text-cfg-emptyText组合框从“文本”字段控件继承了它。
答案 1 :(得分:0)
我设法解决了这个问题。
我将forceSelection
设置为“ true”,并添加了beforeBlur函数,如下所示:
Ext.define('RgiApp.view.ImjestoTipObjektaCombo2', {
extend: 'Ext.form.field.ComboBox',
alias: 'widget.imjestoTipObjektaCombo2',
requires: 'RgiApp.store.ImjestoTipObjektaStore2',
fieldLabel: 'Vrsta obilježja II',
name: 'vrstaobiljezjaid2',
displayField: 'name',
valueField: 'id',
matchFieldWidth: true,
queryMode: 'local',
forceSelection: true,
typeAhead: true,
minChars: 2,
store: 'RgiApp.store.ImjestoTipObjektaStore2',
// Allow empty value in combobox
beforeBlur: function(){
var value = this.getRawValue();
if(value == ''){
this.lastSelection = [];
}
this.doQueryTask.cancel();
this.assertValue();
}
});
没有更多的零,现在,如果数据库中的记录为空,则组合框为空,并且允许我删除值,以便我可以提交NULL。