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

Custom validation attributes are ignored.

6 Answers 728 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ben
Top achievements
Rank 1
ben asked on 06 Jun 2012, 05:30 PM
Hello there,

I have a quick question on how the grid picks up the validation attribute we have on the model.  My grid has batch editing enabled and there's a column bound to the "Name" property of my model.  The Name property is decorated with the [Required] attribute and the required field validator works out of the box, which is nice.  However if I replace [Required] with [RequiredCustom] (where RequiredCustomAttribute is my own class that extends RequiredAttribute), the grid will ignore it and the required field validation will not kick in.  The reason for having the RequiredCustomAttribute is so I can have a logic to build up the validation message from the database.  Back in the old days of Telerik ASP.NET MVC, the grid didn't have any issue picking up my [RequiredCustom].  Has there been a change in this area for Kendo UI for MVC?

Thanks,

Ben

6 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 11 Jun 2012, 11:25 AM
Hello Ben,

As you may know the grid editing feature does use KendoUI Validator component to validate user input. Thus, in order custom validation rules to work you will need to register them with KendoUI Validator. I have attached a small sample which demonstrates possible implementation.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ben
Top achievements
Rank 1
answered on 11 Jun 2012, 03:55 PM
Hello Rosen,

Sorry if the thread title is a little misleading.  The validator I was referring to is not actually a real custom validator that extends ValidationAttribute and implements IClientValidatable.  In fact my validator is just a class that extends the RequiredAttribute and has no client logic involved.  Below is what it looks like.

public class MyRequiredAttribute : RequiredAttribute
{
      public MyRequiredAttribute() { /* logic to initialize the default message */ }
}

Back in Telerik Extensions for ASP.NET MVC, I was able to replace [Required] with [MyRequired] and didn't have to write any code.  For Kendo UI wrapper, [MyRequired] is ignored.

But thank you for the sample you provided - I'm sure it will come in handy when I hook up my other validators.

Thanks,

Ben
0
Rosen
Telerik team
answered on 12 Jun 2012, 07:00 AM
Hello Ben,

Could you please provide a small sample which demonstrates the use of this custom attribute using only plain ASP.NET MVC 3 infrastructure and an edit form?

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ben
Top achievements
Rank 1
answered on 13 Jun 2012, 05:23 PM
Hello Rosen,

Here is the sample project that demonstrates the issue I'm having.  You can see that [MyRequired] attribute is ignored.  And if you swap it with [Required], which I have commented out, the required field validation will work as expected.  Please let me know if you have any questions.  Thanks!

Ben
0
Rosen
Telerik team
answered on 14 Jun 2012, 05:51 AM
Hi Ben,

I asked you to provide a sample without the KendoUI as it seems that this validation attribute approach does not work with the MVC validation too. Please refer to the attached project which demonstrates this.  Let me know if I'm missing something obvious.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ben
Top achievements
Rank 1
answered on 14 Jun 2012, 07:43 AM
Hi Rosen,

Thanks for pointing out that the approach I use doesn't work with the standard ASP.NET MVC.  I've been assuming it should work as it used to work in some version of ASP.NET MVC.  Since this is no longer a Kendo UI issue, I'll go find an answer elsewhere.  I might end up deriving from ValidationAttibute and implementing IClientValidatable so I can hook things up the way you suggested earlier.  Thanks again for looking into this.  

Regards,

Ben
Tags
Grid
Asked by
ben
Top achievements
Rank 1
Answers by
Rosen
Telerik team
ben
Top achievements
Rank 1
Share this question
or