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

[Solved] Displaying custom Validation messages on the Edit form

3 Answers 84 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.
Reid
Top achievements
Rank 2
Reid asked on 11 Mar 2012, 08:13 PM
Hello all,

How can I emit a custom message on the Popup form when the Grid is set to Popup mode?  This is a case where one of a set of checkboxes (Roles) need to be selected for the model to be valid. 

I have implemented the IValidatableObject interface and the implemented method checks for the roles selection and using "Yield" returns the message if no roles are selected.  The view does not display anything other than the inline model fields.  Is there a way to display custom Validation messages (or any others for that matter) inside the Pop-up editor form?

One more if someone knows it, where can you modify the popup hint that displays the violation, that for me I now see with a black background?

Thanks,
Reid

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 14 Mar 2012, 05:31 PM
Hello Reid,

If your Grid is bound via Ajax you should use OnError client event to manually display the errors to the user.
Please check the attached project I created to show you a custom validation using the IClientValidatable interface.
I hope this helps.

Greetings,
Petur Subev
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.
0
Reid
Top achievements
Rank 2
answered on 14 Mar 2012, 08:44 PM
Hello Petur,

Thanks for providing a great example.  I am getting a JS error, "e.modelstate" is undefined when I click the update button.

This scenerio is a UserControl (PayerUserModel.aspx) that supports the custom Edit Template for the row.  I am not sure where to place the JS, I assume in the parent template, in this case ManageUsers.aspx.  I put the JS there and get this error.

Can you suggest what might be going wrong?

Thanks,

Reid
0
Petur Subev
Telerik team
answered on 16 Mar 2012, 12:26 PM
Hi Reid,

OnError is executed each time there is an error as the name suggest, so sometimes there can be another type of error (not a modelstate one). So you should check whether that modelState field exist.
i.e.
if (e.modelState && e.modelState.customError) {
    $(e.modelState.customError.errors).each(function () {
        $('#Personsform').prepend('<div class="field-validation-error">' + this + '</div>')
    });
}

I hope this helps. 

Greetings,
Petur Subev
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
Reid
Top achievements
Rank 2
Answers by
Petur Subev
Telerik team
Reid
Top achievements
Rank 2
Share this question
or