This example is based on GridView - Batch Editing - A simple implementation of an EditItem template and details how to enable client-side unobtrusive validation:
1) Wrap the GridView in a form:
2) Since GridView is bound to the list of values, it's necessary to bind the EditItemTemplate editor to an item's model property from this list:
CS:
4) The ASPxClientEdit.GetIsValid and ASPxClientEdit.GetErrorText methods allow passing validation information from the editor to GridView cells in ASPxClientGridView.BatchEditRowValidating:
5) It's necessary to set MVCx.validateInvisibleEditors to true in the client-side Init event handler to force validation for all cells
1) Wrap the GridView in a form:
[C#]<formid="myForm">@Html.Action("GridViewPartial")</form>
2) Since GridView is bound to the list of values, it's necessary to bind the EditItemTemplate editor to an item's model property from this list:
CS:
[C#]settings.Columns.Add(column=>{column.FieldName="C1";column.SetEditItemTemplateContent(c=>{Html.DevExpress().SpinEditFor(m=>m.FirstOrDefault().C1,spinSettings=>{spinSettings.ShowModelErrors=true;spinSettings.Properties.ValidationSettings.Display=Display.Dynamic;spinSettings.Width=System.Web.UI.WebControls.Unit.Percentage(100);spinSettings.Properties.ClientSideEvents.KeyDown="C1spinEdit_KeyDown";spinSettings.Properties.ClientSideEvents.LostFocus="C1spinEdit_LostFocus";}).Render();});});
VB:
3) The $.valid method in the ASPxClientGridView.BatchEditEndEditing event handler is required to force validation when a currently edited cell loses focus:[VB.NET]settings.Columns.Add(Sub(column) column.FieldName = "C1" column.SetEditItemTemplateContent(Sub(c) Html.DevExpress().SpinEditFor(Function(m) m.FirstOrDefault().C1, Sub(spinSettings) spinSettings.Name = "C1" spinSettings.ShowModelErrors = True spinSettings.Properties.ValidationSettings.Display = Display.Dynamic spinSettings.Width = System.Web.UI.WebControls.Unit.Percentage(100) spinSettings.Properties.ClientSideEvents.KeyDown = "C1spinEdit_KeyDown" spinSettings.Properties.ClientSideEvents.LostFocus = "C1spinEdit_LostFocus"EndSub).Render()EndSub)EndSub)
[JScript]function Grid_BatchEditEndEditing(s, e){var editItemTemplateColumn = s.GetColumnByField("C1");if(!e.rowValues.hasOwnProperty(editItemTemplateColumn.index))return; $("#myForm").valid();var cellInfo = e.rowValues[editItemTemplateColumn.index]; cellInfo.value = C1.GetValue(); cellInfo.text = C1.GetText(); C1.SetValue(null);}
4) The ASPxClientEdit.GetIsValid and ASPxClientEdit.GetErrorText methods allow passing validation information from the editor to GridView cells in ASPxClientGridView.BatchEditRowValidating:
[JScript]function Grid_BatchEditRowValidating(s, e){var editItemTemplateColumn = s.GetColumnByField("C1");var cellValidationInfo = e.validationInfo[editItemTemplateColumn.index];if(!cellValidationInfo)return; cellValidationInfo.isValid = C1.GetIsValid(); cellValidationInfo.errorText = C1.GetErrorText();}
5) It's necessary to set MVCx.validateInvisibleEditors to true in the client-side Init event handler to force validation for all cells
[JScript]function OnInit(s, e){ MVCx.validateInvisibleEditors = true;}