PDA

View Full Version : How to validate new value in CellEditing plugin



Ankit.Desai
30 Mar 2012, 8:59 AM
In reference to this thread
<a href="showthread.php?4590-Changing-User-Grid-Edits-Before-Rendering">http://www.sencha.com/forum/showthread.php?4590-Changing-User-Grid-Edits-Before-Rendering</a>

I am unable to capture new value in validateedit listener so, unable to validate it. my code is as below


var pressureGridNew = new Ext.grid.GridPanel({
id: "pressure-grid",
dd: 'gridDDGroup',
store: pressureGridStoreNew,
columns: pressureCols,
enableDragDrop: true,
stripeRows: true,
autoExpandColumn : 'name',
width:610,
height: 400,
plugins:[cellPressureEditing],
enableColumnHide : false,
viewConfig: {
getRowClass: function(record) {
return 'green-row';
}
}
});


pressureGridNew.on({
validateedit: function(editor,e,eOpts){
alert('hi='+e.field);
}
});

I am working on to validate e.field = shore value. value in editor combo is 0-9.

Now e.record.data[shore] should be new value at the time of validateedit event. I have two scenarios here.

1.If I have entered the value between 0-9 than e.record.data[shore] shows me old value in firebug and once I pass the listener, it will display changed value(new value) in grid.

2. If I have entered other value than 0-9 than e.record.data[shore] still shows me old value in firebug and once I pass the listener, it will display either blank or old value in grid.

When I say pass the listener , I am passing all debug points in listener and the end of editing.

Hope to see some response.

-Ankit

mitchellsimoens
30 Mar 2012, 10:16 AM
What Ext JS 4 version are you using? Back in July 2011 I fixed this but someone else came back to change where the value is placed. Using the following override (tested with 4.1.0 RC1), can you tell me if this fixes the CellEditing plugin?


Ext.define('Override.grid.plugin.CellEditing', {
override : 'Ext.grid.plugin.CellEditing',

onEditComplete : function(ed, value, startValue) {
var me = this,
grid = me.grid,
activeColumn = me.getActiveColumn(),
record;

if (activeColumn) {
record = me.context.record;

me.setActiveEditor(null);
me.setActiveColumn(null);
me.setActiveRecord(null);

me.context.value = value;

if (!me.validateEdit()) {
me.context.value = startValue;
return;
}
// Only update the record if the new value is different than the
// startValue. When the view refreshes its el will gain focus
if (!record.isEqual(value, startValue)) {
record.set(activeColumn.dataIndex, value);
// Restore focus back to the view's element.
} else {
grid.getView().getEl(activeColumn).focus();
}
me.fireEvent('edit', me, me.context);
}
}
});

If it works for you then I will get this merged into the framework to fix this. The red text is just to remind me what I changed.

Ankit.Desai
30 Mar 2012, 10:41 AM
Thanks for quick reply mitchellsimoens,

I am using version 4.0. I tried your piece of code in my code. It does compile at load of script but when I tried to edit, function onEditComplete won't be called. I have some break points in the over ride definition.


var cellPressureEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1,
listeners : {
beforeedit : function(e) {

if(top.siteAccess=='View' || top.viewModeDisplay == true ){
if(e.colIdx == 0 || e.colIdx == 1 || e.colIdx == 2){
return true;
}else{
return false;
}
} else{
if(e.colIdx == 0 || e.colIdx == 1 || e.colIdx == 2){
return true;
}
else {
return true;
}
}
},
afteredit: function(e) {
//cell value has been changed without saving
top.pressureChanged = true;
cellFieldChange();
}
}
});


Ext.define('Override.grid.plugin.CellEditing', {
override : 'Ext.grid.plugin.CellEditing',

onEditComplete : function(ed, value, startValue) {
var me = this,
grid = me.grid,
activeColumn = me.getActiveColumn(),
record;

if (activeColumn) {
record = me.context.record;

me.setActiveEditor(null);
me.setActiveColumn(null);
me.setActiveRecord(null);

me.context.value = value;

if (!me.validateEdit()) {
me.context.value = startValue;
return;
}
// Only update the record if the new value is different than the
// startValue. When the view refreshes its el will gain focus
if (!record.isEqual(value, startValue)) {
record.set(activeColumn.dataIndex, value);
// Restore focus back to the view's element.
} else {
grid.getView().getEl(activeColumn).focus();
}
me.fireEvent('edit', me, me.context);
}
}

});

So right now my script has both plugin quoted above. Mine and yours.

Let me know if I missed something. Do we have to wrap and treat that " onEditComplete " under " listeners " ?

-Ankit

Ankit.Desai
2 Apr 2012, 11:06 AM
If I can get new value I can validate it from back end but even I am not getting entered value as new value.Some time if I enter any value other than listed value, cell goes blank and than blank will be new value in

e.record.data[shore] so, view will also have blank as new value.

Any one ?

-Ankit