View Full Version : Grid: Server side validation
Hello,
additionally to the client side validation, I have to set up a server side validation of an editable grid (when the user decides to make his changes persistent). To this end, I would like to be able to re-render the grid with the appropriate error messages in each field. What is the best practice for doing that?
Thank you,
Massimo
jack.slocum
7 Apr 2007, 6:59 AM
I personally have no experience with this use case. However, I would probably add a css class and qtip to the cells that contain invalid data by using a custom renderer on the editable cells. Your server response should probably be in a format that allows for speedy record matching, e.g.:
{
errors: {
'some-record-id' : {'firstName': 'My validation message', 'company': 'Company Foo is not allowed'},
'some-other-id' : {'lastName': 'My other message'}
}
};
Then your renderer would closure in a variable that holds any error messages. In the example below, that variable is called "errors":
function renderFirstName(value, params, record){
if(errors[record.id] && errors[record.id].firstName){
params.cls = 'my-error-class';
params.attr = 'ext:qtip="'+Ext.util.Format.htmlEncode(errors[record.id].firstName).'"';
}
// do something else?
return value;
}
This is too much code to do over and over and I would recommend extending the GridView or ColumnModel to provide the functionality automatically.
Note: after receiving validation messages, you would need to call grid.getView().refresh().
Thank you Jack, I will try it out.
Massimo
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.