This is a migrated thread and some comments may be shown as answers.

Batch Editing validation

1 Answer 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Matthew
Top achievements
Rank 1
Matthew asked on 05 Dec 2011, 07:00 PM

I am using batch editing in a Grid.  Validation does not work in all cases.  For example, if I add a record and the first two fields are textboxes and both are required, the grid will notify me if I don't have a value in the first textbox and try to save.  However, if I fill out the first textbox but leave the second textbox blank and click on another record I don't get any message stating a value is required for the 2nd textbox.  Worse, when I press the save button the grid attempts to save the record and an error occurrs because I'm trying to insert a record with a null value in a required field.

I'm using ORM to create the entities model, and then I'm adding data annotations (see below):

private string _HookNum;
[Required(ErrorMessage = "Required")]
[StringLength(15, ErrorMessage = "Max 15 Characters")]
public virtual string HookNum  { get { return this._HookNum; } set { this._HookNum = value; } }
 
private string _HookName;
[Required(ErrorMessage = "Required")]
[StringLength(30, ErrorMessage = "Max 30 Characters")]
public virtual string HookName  { get { return this._HookName; } set { this._HookName = value; } }

Remember, the first textbox (HookNum) is validated correctly, but the second (HookName) is not.

I have client events specified for trapping errors on the grid (see below):

//Happens on client (ajax)
.ClientEvents(e => {
    e.OnDataBinding("Grid_onDataBinding");
    e.OnError("Grid_onError");
})

And the javascript function is specified (see below):

function Grid_onError(args) {
    if (args.textStatus == "modelstateerror" && args.modelState) {
        var message = "Errors:\n";
        $.each(args.modelState, function (key, value) {
            if ('errors' in value) {
                $.each(value.errors, function () {
                    message += this + "\n";
                });
            }
        });
        alert(message);
    }
}

If I click on the second textbox, then press save, then approprate validation occurrs.  I have seen other posts that suggest this is a known limitation of batch editing mode, but surely there must be a reasonable method of traping server errors and presenting error messages in the grid.

What am I missing?










1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 08 Dec 2011, 09:36 AM
Hello Matthew,

The described behavior is expected. Since the second cell never gets in edit mode there is no way to perform the usual client-side validation.
There is no easy way to show the error messages in the Grid because there could be multiple errors, on multiple rows. To make it work, you should somehow locate the corresponding table cells and set their content to the error message. Another option would be to find the first cell which has validation error and simulate a mouse click on it (to make it go in edit mode).



All the best,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or