Hi Saki & MJ
Thanks a lot for the information. I will go through these tuturials starting today.
~Rave
Printable View
Hi Saki & MJ
Thanks a lot for the information. I will go through these tuturials starting today.
~Rave
Back to the GridValidator ;)
I changed the isCellValid function so that it ignores a currently focused field in the grid. Otherwise the line within the "if" clears out any typed in value. I am catching the "clientvalidation" event in FormPanel and using FormPanel's monitorResize (gray out submit button until valid). I extended both FormPanel and GridValidator. The code below could not be extended. I'll give more details if anyone has interest.
PHP Code:isCellValid:function(col, row) {
if(!this.colModel.isCellEditable(col, row)) {
return true;
}
var ed = this.colModel.getCellEditor(col, row);
if(!ed) {
return true;
}
var record = this.store.getAt(row);
if(!record) {
return true;
}
var field = this.colModel.getDataIndex(col);
var isValid = false; // if hasFocus, assume not yet valid
if ( !ed.field.hasFocus ) {
ed.field.setValue(record.data[field]);
isValid = ed.field.isValid(true);
}
return isValid;
} // end of function isCellValid
Do you mean monitorValid?
I don't understand that comment?
Sure, post what you got. Any criticism only helps everyone? ;)
i added "validateModifiedOnly" for those who want check editet fields only:
PHP Code:/**
* EditorGrid validation plugin
* Adds validation functions to the grid
*
* @author Jozef Sakalos, aka Saki
* @version 0.1
*
* Usage:
* grid = new Ext.grid.EditorGrid({plugins:new Ext.ux.plugins.GridValidator(), ...})
*/
Ext.ux.plugins.GridValidator = function(config) {
// initialize plugin
this.init = function(grid) {
Ext.apply(grid, {
/**
* Checks if a grid cell is valid
* @param {Integer} col Cell column index
* @param {Integer} row Cell row index
* @param {Boolean} validateModifiedOnly true to validate modified fields only
* @return {Boolean} true = valid, false = invalid
*/
isCellValid:function(col, row, validateModifiedOnly) {
if(!this.colModel.isCellEditable(col, row)) {
return true;
}
var ed = this.colModel.getCellEditor(col, row);
if(!ed) {
return true;
}
var record = this.store.getAt(row);
if(!record) {
return true;
}
var field = this.colModel.getDataIndex(col);
if(!record.isModified(field)) {
return true;
}
ed.field.setValue(record.data[field]);
return ed.field.isValid(true);
} // end of function isCellValid
/**
* Checks if grid has valid data
* @param {Boolean} editInvalid true to automatically start editing of the first invalid cell
* @param {Boolean} validateModifiedOnly true to validate modified fields only
* @return {Boolean} true = valid, false = invalid
*/
,isValid:function(editInvalid, validateModifiedOnly) {
var cols = this.colModel.getColumnCount();
var rows = this.store.getCount();
var r, c;
var valid = true;
for(r = 0; r < rows; r++) {
for(c = 0; c < cols; c++) {
valid = this.isCellValid(c, r, validateModifiedOnly);
if(!valid) {
break;
}
}
if(!valid) {
break;
}
}
if(editInvalid && !valid) {
this.startEditing(r, c);
}
return valid;
} // end of function isValid
});
}; // end of function init
}; // GridValidator plugin end
any one please help me.
Can i use this file as separate file ?