Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
75
Validation in WebGrid
posted

Hello,

I have a webgrid with 3 columns. One for description/name and another 2 for a start date and for an end date. I have used a BeforeRowUpdateHandler for validating. It does prompt me if the name column is blank or if the start date is greater than end date. However, if I enter a value in the name column and should save, I would get an error something about not locating the item since ID is null. I tried adding a BeforeRowInsertHandler but I couldn't get the row since the record is being added through the 'Add New' row. Here's the javascript I used.

function GridAddressTypes_BeforeRowUpdateHandler(gridName, rowId){

    var row = igtbl_getRowById(rowId);
    var start_date = new Date(row.getCellFromKey("start_date").getValue());
    var end_date = new Date(row.getCellFromKey("end_date").getValue());
       
    var description = row.getCell(1).getValue();
   
    if(description != null)
    {
        if(start_date > end_date){
        window.alert("Start Date can't be greater than End Date");
        return true;
        }
        return false;
    }else
    {  
        window.alert("Description can't be blank.");
        return true;
    }
   
}

How can I make this work? Thanks in advance. =)