I want certain fields to be required. Is there a property or event that I should use for this?
Assign a required field validator to the column. Then when the user tries to move from the cell, if it's blank or null then validator the error message will pop up below the cell and won't let them tab away. No extra javascript required.
it doesn't work.
If control is editable and add new rows is allowed then used can add new row and validation will not be applied to current row. Here are issues:
1) I have a requiredFieldValidator to a couple of my columns. It does validate when you step into those required cells. However, when I input a data into a required cell, and then add a new row, it doesn't validate the rest of the cells in my last row.
2) Client-side event BeforeExitEditMode, in this function the "cellvalue" is always old value, so we can't build custom validator for a cell.
function UWG_CustomerContact_BeforeExitEditMode(tableName, cellName)
{
var cell = igtbl_getCellById(cellName);
var cellvalue = cell.getValue();
}
we tested it with version started from 2007.1 up o 2008.
1. I have tried with requiredFieldValidator as well and even though it works when you edit one row the validation error message is displayed below the cell that has the empty value, which means that the error message can be displayed in the middle of the grid which does not look nice at all. I have found no way to get the validation to display where it is designed to be e.g. above or below the grid.
2. cell.getValue will get the current value of the cell, not the new value. You should use newValue parameter for this. Something like this (works with 2008.2). Unfortunately none of the examples in the KBase etc. has an example of this. But in the client side event reference you can see that the newValue parameter is listed. I guess it has been added in some of the later versions.
http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR2.0/html/WebGrid_Client_Side_Events_CSOM.html
function BeforeExitEditMode(gridName, cellID, newValue){ //get the cell var cell = igtbl_getCellById(cellID);
//If the value is not null or empty string or is equal to the existing value then allow the change if ((newValue != null && newValue != "") || (newValue == cell.getValue())) { //if the value is not null or empty or equal to existing value then it's ok to exit edit mode return 0; } alert("Please enter a value."); return 1;}
RegardsFredrik