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

DatePicker validation message - data-val-date

2 Answers 1789 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Jiri
Top achievements
Rank 1
Jiri asked on 20 Jul 2016, 09:31 AM

Hello, 

I have a problem  with validation message for DatePicker in UI for ASP.NET MVC. 

Property in model:

[DataType(DataType.Date, ErrorMessage = "Please enter a valid date. - TEST")]
public DateTime FromDateTime { get; set; }

Part of my cshtml file:

@(Html.Kendo().DatePickerFor(model => model.Filter.FromDateTime)
.Name("Filter.FromDateTime")
.Format(DateTimeFormats.DateTimeFormat)
.ParseFormats(DateTimeFormats.ParseFormat)                         
.HtmlAttributes(new {@class = "form-control", style = "width: 100%"})
)
@Html.ValidationMessageFor(model => model.Filter.FromDateTime, "", new { @class = "text-danger" })

This is part of the html page which is generated from the cshtml file:

<input name="Filter.FromDateTime" class="form-control k-input input-validation-error" id="Filter_FromDateTime" role="combobox" aria-disabled="false" aria-expanded="false" aria-invalid="true" aria-required="true" aria-describedby="Filter_FromDateTime-error" aria-owns="Filter_FromDateTime_dateview" style="width: 100%;" type="text" value="20. 4. 2016" data-val-required="Toto datum musí být vyplněno." data-val-date="The field FromDateTime must be a date." data-val="true" data-role="datepicker">

Image of the part of the html page from webbrowser is in file "datepickerError.png".

The problem is in the content of the validation message. Message in my model is "Please enter a valid date. - TEST" but message in html is "The field FromDateTime must be a date." 

I want to create localization of this message and change its content. How can I do it?

Thank you for your advice.

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 22 Jul 2016, 06:50 AM
Hello,

The date validation is generated implicitly by MVC and the message does not depend on the DataType attribute. It is possible to use the approach demonstrated in this blog post to localize the messages for dates and numbers. 

Regards,
Daniel
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jiri
Top achievements
Rank 1
answered on 22 Jul 2016, 01:16 PM
Thank you very much.
Tags
Date/Time Pickers
Asked by
Jiri
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Jiri
Top achievements
Rank 1
Share this question
or