GavinSinai wrote:
OK Thats great. I have done everything you have said.
(1) The Validator's BeforeSave() method throws an ORMEntityValidationException
(2) The field validator uses SetEntityFieldError() and returns false if the field concerned is not valid.
Everything works except for the fact that:
Field Validation forbids a field from holding invalid values. Thats ok, but corresponding databound fields(e.g. gridview cells) are also forbidden from holding those values. As the user navigates away from the gridview field s/he has just modified, the field value reverts back to the original value.
E.g. invalid phone number, all the user may need to do is remove an invalid character, now they have to re-enter the phone number.
Its clear that the entity can't contain invalid data, but the grid view cell most certainly can (along with an error icon to indicate that the cell is not in a valid state). If the grid view is forced to be synchronized with the entity, then the user experiences data loss (which really isn't a good thing).
How to balance the integrity of the entity versus the useability of the application? Is there a best practise?
Regards
Gavin
Hi, I'm in the same situation, we are using LLBLGen 2.5 and WinForms / Infragistics 6.3 (I need to do the upgrade to 7.2 one of these day...
the possibility to hold the invalid data is a configuration you need to do on the ultragrid properties:
on the UgCellDataError event, you need to set the following event properties
e.StayInEditMode = True
e.RaiseErrorEvent = True 'tell the ultragrid to generate the [Error] event
and, on the ultragrid [error] event
If e.DataErrorInfo IsNot Nothing Then
'don't show ultragrid message box error
e.Cancel = True
'if ther is no error setted on this column...
If DirectCast(e.DataErrorInfo.Cell.Row.ListObject, System.ComponentModel.IDataErrorInfo).Item(e.DataErrorInfo.Cell.Column.Key) = "" Then
'use the error generated by the ultragrid (this happen when you set an inossible date like "30/02/2000" in a datepicker control or similar things)
DirectCast(e.DataErrorInfo.Cell.Row.ListObject, EntityBase2).SetEntityFieldError(e.DataErrorInfo.Cell.Column.Key, e.ErrorText, False)
End If
End If
other things we do:
*) on the AfterCellCancelUpdate event, we reset the error on the entity column
DirectCast(e.Cell.Row.ListObject, EntityBase2).SetEntityFieldError(e.Cell.Column.Key, "", False)
*) setup the grid to show the error set by the validator
mUGrid.DisplayLayout.Override.SupportDataErrorInfo = SupportDataErrorInfo.RowsAndCells
Anyway, we hardly force this type of per-field validation, because in this case the user is locked in the current field and cant go out without correcting the data.
We, instead, prefer to do all the checking in the beforeEntitySave event, so the user can't save the entity with wrong data, but with a single click can see all the error (the single click is when the user click the SAVE button
.