How can I validate on a Master/Details page that at least one detail record must be enter
Validate Master/Detail to have at least one detail
-
- User
- Posts: 88
Please notes that there are a form value named "key_count_f<detail table name>grid" which is stored the number of detail record to be insert.
Also there are an function to check the empty row of detail record named "EmptyRow", it will return true if the row is empty.
So you may consider to add the checking in "Form_CustomValidate" Client Script of Add Page.
Example as Demo Project: Master/Details relationship between Orders and Order_Details Table.
In "Form_CustomValidate"
var cnt = 0;
for (i=1; i<=fobj.key_count_fOrder_Detailsgrid.value; i++) {
if (!fOrder_Detailsgrid.EmptyRow(i)) {
cnt++; //number of rows with value.
}
}
Return true or false base on your requirement.
-
- User
- Posts: 15
Thanks, this should be on the User Submited Tips (ASP.NET Maker).
Here is the complete code for the Demo Project: Master/Details relationship between Orders and Order_Details Table.
var cnt = 0;
for (i=1; i<=fobj.key_count_fOrder_Detailsgrid.value; i++) {
if (!fOrder_Detailsgrid.EmptyRow(i)) {
cnt++; //number of rows with value.
}
}
if (cnt == 0)
return ew_OnError(this, fobj.elements["x1_ProductID"], ewLanguage.Phrase("EnterRequiredField") + " - @(ew_RemoveHtml(ew_JsEncode2(Order_Details.ProductID.FldCaption)))");
return true;