PDA

View Full Version : Stop RowEditing plugin from completing the edit on keypress 'enter'



fennecFox
20 Oct 2014, 8:38 AM
Hi

I'm using the RowEditing plugin. If you select 'enter' on the keyboard within a textfield editor while the row is in edit mode, the roweditor saves the whole row (completeEdit is called). I don't want this behavior - the row editor should only save the row when a user clicks on the save button.

Does anyone know how to stop the rowediting saving on 'enter'? I've tried overriding 'RowEditor' and 'RowEditing' to remove the 'enter' on the KeyNav but it's not working.

I'm using 4.1.3

scottmartin
20 Oct 2014, 2:12 PM
You could perform it at the plugin level:



Ext.define('Ext.grid.plugin.override.RowEditing', {
override: 'Ext.grid.plugin.RowEditing',

onEnterKey: function() {
if (this.getEditor().getForm().isValid()) {
//this.completeEdit();
}
}

});


Or at the editor level



{
text : 'Name',
dataIndex : 'name',
flex : 1,
editor : {
xtype : 'textfield',
enableKeyEvents : true,
listeners : {
keydown : function(field, e) {
if (e.getKey() == e.ENTER) {
e.stopEvent();
}
}
}
}
},

fennecFox
21 Oct 2014, 2:43 AM
Thanks

I've tried performing it at the plugin level as you describe and it doesn't work - it never enters that event. I've tried the same for the internal 'roweditor' and the 'onEnter' function is never called. I've also tried overriding the KeyNavs for both and still that doesn't have any affect.

I guess I have no option right now to put the enter event handler on the individual editors themselves. However, I have quite a few editors which appear when the row enters edit mode, so it's not ideal adding the event listeners for the enter event on all of them.

scottmartin
21 Oct 2014, 6:46 AM
Turns out I had tested on 4.2.2 where there was a issue with form.valid and it was not do anything on 'enter' regardless of the override.

If you look at the code, you will see that Ext.grid.RowEditor has a keyNav for the enter, esc. You can remove binding to get past this.

fennecFox
21 Oct 2014, 8:45 AM
Turns out I had tested on 4.2.2 where there was a issue with form.valid and it was not do anything on 'enter' regardless of the override.

If you look at the code, you will see that Ext.grid.RowEditor has a keyNav for the enter, esc. You can remove binding to get past this.

Thanks scottmartin - I tried this but it also didn't work! Was quite baffled as I removed all bindings and the enter event was still propagating up for some reason. I removed keyNav bindings on RowEditing and RowEditor

rhubarb65
29 Dec 2014, 5:14 AM
onEnterKey seems to have disappeared from rowEditing in 5.1.0

I want to be able to hit Enter on a readonly field and cause an event to be fired instead of starting the rowEditing

Overriding onEnterKey (empty) and a listener on the grid panel seemed to work



cellkeydown: function(cell, td, cellIndex, record, tr, rowIndex, e, eOpts) {
if (e.getKey() == e.ENTER) {
var rowEditing = this.getPlugin('rowEditing');

if (cellIndex === 0) {
this.fireEvent('do_something', record.get('record_id'));
} else {
rowEditing.startEdit(rowIndex, cellIndex);
}
}
}


The "keyDown" example didnt work either (e doesnt seem to be an event)

So now I am stuck

Peter