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

Validation doesn't take into account lower case characters

1 Answer 151 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Howard
Top achievements
Rank 1
Howard asked on 27 Mar 2014, 11:54 PM
Hi Telerik Team,

I've a time picker and when I put lower case characters in, validation is false, like instead of PM if I put pM, I get the following message as in the picture.

Also the validation message is not coming from Data Annotation.

Please let me know.

Thank you

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 31 Mar 2014, 12:46 PM
Hi Niroj,

I posted an answer to the support thread opened on the same subject. Here is a quote of the answer:

Straight up to your questions:

#1:
Kendo Validator uses a special mvcdate rule, which internally calls kendo.parseDate to determine whether the input is a valid date. As you can see when no formats are passed, the method will uses a list of formats defined in the current Kendo culture to validate the input. In this case, it successfully parse 10:00 pM as a 10:00 and does not show error message. You can overcome this overriding the mvcdate rule (do this after the grid declaration):
<script>
    var originMvcDate = kendo.ui.validator.rules.mvcdate;
 
    kendo.ui.validator.rules.mvcdate = function (input) {
        var format = input.attr("data-format");
        if (format) {
            return kendo.parseDate(input.val(), format);
        }
        return originMvcDate(input);
    }
</script>

The next step is to add a specific format, that the validator will use:
//TimePicker editor cshtml page
 
...
.HtmlAttributes(new { data_format="hh:mm tt" })
...

#2:
The error message defined in DateTypeAttribute is ignored when a unobtrusive attributes are rendered by the ASP.NET MVC framework. The first option to overcome this is to set the error message manually:
.HtmlAttributes(new { data_format="hh:mm tt", data_val_date="Your error" })
The other option is to use the approach discussed here.

I will ask you to continue our conversation in only one thread to avoid any duplication.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Date/Time Pickers
Asked by
Howard
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or