Wednesday, August 6, 2008

Javascript validations for infragistics grid

function IsRowChecked()
{
var bret = false;
var grid = igtbl_getGridById("sg");
var count = grid.Rows.length;
var checked = true;
var rowcount = 0;
var i;
var errMsg = "";

for (i = 0; i < count; i++)
{
var row = grid.Rows.getRow(i);
checked=row.getCell(0).getValue();
if(checked == "true")
{
rowcount++;
}
if(rowcount > 1){break;}
}

if (rowcount == 0)
{
errMsg += "Please check a checkbox to select a single customer.";
bret = false;
}
else if (rowcount == 1)
{
bret = true;
}
else if (rowcount > 1)
{
errMsg += "Please select only a single customer.";
bret = false;
}

//return bret;
if (errMsg == "")
{
return confirm("Are you sure that you want to clear the Quickbooks ID for the selected company?");
}
else
{
alert(errMsg);
return bret;
}
}


function checkCustomerLength()
{
var bret = false;
var grid = igtbl_getGridById("sg");
var count = grid.Rows.length;
var checked = true;
var rowcount = 0;
var i;
var customername;
var errMsg = "";

for (i = 0; i < count; i++)
{
var row = grid.Rows.getRow(i);
checked=row.getCell(0).getValue();
if(checked == "true")
{
customername = row.getCell(2).getValue();
if(customername.length > 40)
{
errMsg += "The customer name (" + customername + ") is greater than 40 characters in length. Please shorten the customer name on the 'Customer Details' page before continuing this operation.";
ret = false;
break;
}

}

}

if (errMsg == "")
{
return true;
}
else
{
alert(errMsg);
return bret;
}
}

No comments: