PDA

View Full Version : Focus jump in RowEditing plugin in Ext.window



rubyrain
20 Sep 2012, 9:17 AM
Hi,

While I was working on something, I encountered a strange problem. I searched forums but couldn't find anything similar to this issue, so here it is. Ext version is 4.1.1. I don't think I had this problem with 4.0.7 but not 100% sure.

I have an editable grid with rowediting plugin, which is inside of Ext.Window.
I use numberfield as editor for 2 columns and have minValue, minLength, maxLength, enforceMaxLength set.
When I start editing a row, and if a field becomes valid from invalid, the focus is lost from the field (I think it is focusing window). This prevents me using 'Enter' key to update the row, or use 'Tab' key to navigate to other editor fields. When editable grid is inside a container that is not floating (that is, other than Ext.Window), it acts as normal.

To reproduce try this code. Once grid inside window shows, click top button to add a row, then start editing.
minLength and maxLength are set to 9. so as you start editing, you get red border, tooltip indicating the field is invalid. As you type 9th number, invalid marks are gone, but as well as the focus.

Not sure this is bug or something in my code. (I tried to make it simple. This is part of more complex app)

Thanks in advance.



Ext.define('BarcodeRange', {
extend: 'Ext.data.Model',
fields: [ 'start', 'end', { name: 'count', type: 'int' } ]
});


Ext.define('BarcodeRanges', {
extend: 'Ext.data.Store',
model: 'BarcodeRange'
});


Ext.onReady(function() {
var bGrid = Ext.create('widget.grid', {
columns: [
{
header: 'Start', dataIndex: 'start', flex: 1, soartable: false,
editor: {
xtype: 'numberfield', itemId: 'startBarcode', maxLength: 9, enforceMaxLength: true, minLength: 9, validateOnChange: false, tabIndex: 1,
hideTrigger: true, minValue: 0, allowDecimals: false
}
},
{
header: 'End', dataIndex: 'end', flex: 1, soartable: false,
editor: {
xtype: 'numberfield', itemId: 'endBarcode', maxLength: 9, enforceMaxLength: true, minLength: 9, validateOnChange: false, tabIndex: 1,
hideTrigger: true, minValue: 0, allowDecimals: false
}
},
{ header: 'Count', dataIndex: 'count', width: 45, soartable: false, align: 'right' },
{
xtype : 'actioncolumn', header : 'Cancel', width : 50, align : 'center', soartable: false,
items : [
{
icon: '/imgs/delete_icon.png', iconCls: 'action-shipment-edit', handler: function(grid, rix, cix) {
grid.getStore().removeAt(rix);
}
}
]
}
],


dockedItems : [
{
xtype: 'toolbar', dock: 'top',
items: [
{
xtype: 'button', text: 'Add Barcode Sequence', icon: '/imgs/add.png',
handler: function(btn, e) {
var newBarcodeRange = Ext.create('BarcodeRange');


btn.up('grid').getStore().add(newBarcodeRange);
btn.up('grid').getPlugin('rowEditor').startEdit(newBarcodeRange, 0);
}
}
]
},
{
xtype: 'toolbar', dock: 'bottom',
items: [
'->',
{
xtype: 'numberfield', itemId: 'partialBarcode', fieldLabel: 'Partial (Optional)',
width: 200, allowDecimals: false, hideTrigger: true,
maxLength: 9, enforceMaxLength: true, minLength: 9, minValue: 0,
listeners: {
errorchange: function(comp, error, eopts) {
var saveButton = comp.up('window').down('button[action=Save]');
if (error === "") {
saveButton.enable();
} else {
saveButton.disable();
}
}
}
}
]
}
],


plugins: [
{ ptype: 'rowediting', pluginId: 'rowEditor', clicksToEdit: 2 }
]
});


var win = Ext.create('widget.window', {
title : 'Barcodes Ranges',
width : 300,
height : 300,
closeAction : 'hide',
closable : false,
modal : true,
layout : 'fit',
buttonAlign : 'right',
buttons : [ { xtype: 'button', action: 'Save', text: 'Save', handler: function() { /*me.saveBarcodes*/ } } ],
items : [ bGrid]
});


win.show();
});

mitchellsimoens
24 Sep 2012, 6:34 AM
This was a bug that should be fixed in a later release. Plus, perf is much greater in 4.1

rubyrain
24 Sep 2012, 7:20 AM
Thanks Mitchell, but is there any temporary fix for this? I'm really pushing for 4.1 upgrade at work (yeah, performance is a lot better in 4.1), but users will be really annoyed if I do nothing about this.

rubyrain
28 Sep 2012, 10:07 AM
For the record, I had to use focus(false, 20) to work around this problem.


{
header: 'Start', dataIndex: 'start', flex: 1, soartable: false,
editor: {
xtype: 'numberfield', itemId: 'startBarcode', maxLength: 9, enforceMaxLength: true,
minLength: 9, vtype: '',
minLengthText:'Required length is 9 digits',maxLengthText:'Required length is 9 digits',
hideTrigger: true, keyNavEnabled: false, mouseWheelEnabled: false, minValue: 0, allowDecimals: false,
listeners: {
errorchange: function(comp, error, eopts) {
comp.focus(false, 50);
}
}
}
},
{
header: 'End', dataIndex: 'end', flex: 1, soartable: false,
editor: {
xtype: 'numberfield', itemId: 'endBarcode', maxLength: 9, enforceMaxLength: true,
minLength: 9, vtype: '', hideTrigger: true,
minLengthText:'Required length is 9 digits',maxLengthText:'Required length is 9 digits',
keyNavEnabled: false, mouseWheelEnabled: false, minValue: 0, allowDecimals: false,
listeners: {
errorchange: function(comp, error, eopts) {
comp.focus(false, 50);
}
}
}
}


Also I had another focus problem if I add a record and used startEdit in window's show event. (it would focus window instead of the editor. I could see that editor field was focused but then the focus jumps to the window. I think window uses some kind of deferred focus) I also worked around this using Ext.defer

wgordon
16 Oct 2012, 12:51 PM
Hi,

I am also experiencing this issue and am running on version 4.1.1. Could you please provide the ticket number so I may track when it is complete?

Thanks.