You found a bug! We've classified it as
EXTJS-17890
.
We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
-
Sencha Premium Member
ComboBox with ForceSelection does not do validation correctly
Hi,
ExtJs Version: 5.1.1
Fiddle: https://fiddle.sencha.com/#fiddle/n6j
ComboBox with 'allowBlank: false' and 'forceSelection: true' is not displaying empty value is invalid.
Reproducing the bug
- goto fiddle
- (combobox is correctly marked as invalid, as no value is selected)
- click inside the combo and type 'xxxxxx'
- now either Tab out of the box, or just click somewhere outside
=> combobox has no value, but is marked as valid
-
Thanks for the report! I have opened a bug in our bug tracker.
-
Sencha Premium Member
For anyone interested in a quick and dirty workaround:
Blur Callback of the Combobox
Code:
blur: function(self) {
if (!this.allowBlank && this.getValue() === null) {
this.markInvalid('This field is required.');
}
}
-
Sencha Premium Member
This Bug is still existing in ExtJS 6.5.3!
I use this as workaround:
Code:
listeners: {
afterrender: function(combo){
combo.validate();
}
}
-
Sencha Premium User
another work around
This override has resolved the issue for me so far:
Code:
override: 'Ext.form.field.ComboBox',
initComponent: function () {
this.callParent();
if (this.allowBlank === false && this.forceSelection === true) {
this.on({
blur: function () {
if (Ext.isEmpty(this.getValue())) {
this.wasValid = false
}
}
})
}
}