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.
Try to add emptyText property to your combobox definition. Ext.form.field.Text-cfg-emptyText Combobox iherits it from the Text field control.
I managed to solve this.
I set forceSelection
to "true" and added beforeBlur function 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: 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();
}
});
There are no more zeroes, now the combobox is blank if record in database is blank and it allow me to delete value so I can submit NULL.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.