Unplanned
Last Updated: 25 Mar 2024 13:30 by ADMIN
Reza
Created on: 23 Mar 2023 09:53
Category: UI for ASP.NET MVC
Type: Feature Request
1
Disable Telerik Validation and Follow Validations from Model

There is a Kendo Validation in addition to ASP.net MVC one. 

There is a need for a method or script to disable the Kendo Validation and enforce the code to follow rules we define in the model.

Currently we have to write validation bypass script for each field, but I am looking for a way to disable Kendo Validations for the entire project or/and for specific page and it follows validation rules from the MVC model.

In most cases, validations from the MVC are sufficient and there is no need for redundance validations from the telerik.

 

7 comments
ADMIN
Ivan Danchev
Posted on: 21 Apr 2023 08:12

Hi Reza,

Ok. In the previously discussed scenarios, validation is triggered based on the data annotations. If you come across a scenario in which this does not happen, feel free to post it here in the Feature Request, so that we can address it.

Regards,
Ivan Danchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Reza
Posted on: 14 Apr 2023 08:32

Hi Ivan,

Thank you for your comment, in general I am looking into a way that by default Telerik get all validations from the Model and whenever I want to add a validation, I should be able to do it in the Model and Telerik follow it.

ADMIN
Ivan Danchev
Posted on: 12 Apr 2023 10:25

Hi Reza,

For the format there is a separate feature request: https://feedback.telerik.com/aspnet-mvc/1598330-telerik-should-follow-changes-in-model-for-datepicker

As for the Email data annotation, the Telerik TextBox works with it and is validated when the entered text is not a valid email: see the attached video.

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Attached Files:
Reza
Posted on: 06 Apr 2023 08:05

Hi Ivan,

For the validation it might work as expected, however try this code:

[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime CustomDate{ get; set; }

I want to set the format to follow the format I shared but when I run Telerik, it follows the default format and not the one in the model. To resolve this issue, you have to use globalization like explain here:

Localization - Kendo UI Globalization - Kendo UI for jQuery (telerik.com)

I simply one whatever model I select, it follows the model.

I also had issue with email which I had a code like

[Required]
[DataType(DataType.EmailAddress)]
[EmailAddress]
public string Email { getset; }

Where EmailAddress would check if the field contains valid email address and it works well with ASP.net project but when we have Telerik UI it didn't work and to solve it I have to replace it with regular expression.

 

ADMIN
Ivan Danchev
Posted on: 06 Apr 2023 07:53

Hello Reza,

The other feature request is for the formatting that is set in the model, as fat as I understand this one is for Required being set in the model, for example:

[Required(ErrorMessage = "StartDate is required.")]
public DateTime StartDate { get; set; }

I tested the scenario and the DatePicker is getting its required attribute from the model and is getting validated. Here's an exemplary view:

@model TelerikMvcApp1.Models.SampleModel

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-ajax-unobtrusive/3.2.6/jquery.unobtrusive-ajax.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.3/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.12/jquery.validate.unobtrusive.min.js"></script>

<script>
    $.validator.setDefaults({ ignore: '' });
</script>

@using (Html.BeginForm("Submit", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.ValidationMessageFor(model => model.StartDate, "", new { @class = "text-danger" })

    @(Html.Kendo().DatePickerFor(m => m.StartDate))
    <input type="submit" value="Submit" />
}

If you leave the DatePicker empty and try to submit the form, the validation message set in the model appears.

Let me know in case I am missing something with regard to reproducing the issue with the DatePicker's validation.

Regards,
Ivan Danchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Reza
Posted on: 30 Mar 2023 07:21

Thank you for your comment, one issue we had was with the date and I set model to follow certain format, but the Telerik followed a different one and I had to do multiple changes to make it work. I file feedback here:

Telerik should follow changes in model for DatePicker

There are cases like I set field should be required or not required in the model, but I saw it won't follow the model and I have to bypass validation in the client. In general, I want Telerik follow exactly all validation rules I define in the model, so it is easier for me to maintain it because if I want to make a change, I just change model. However, in current situation, I need to change view.

ADMIN
Ivan Danchev
Posted on: 30 Mar 2023 06:47

Hello Reza,

Could you please provide more context and an example of a use case, where you need to bypass the built-in validation, so that the validation rules from the model are applied? Along with explaining the use case, can you elaborate more on what the actual behavior of the specific component is  and what the expected behavior is in that use case?

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.