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

Format-issues using DatePicker

1 Answer 321 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
CAD-OD
Top achievements
Rank 1
CAD-OD asked on 16 Jun 2015, 10:52 AM

Hi,

I've got a property in my model:

DateTime _ValidTo;
[DisplayName("Gültig bis")]
[DataType(DataType.Date, ErrorMessage="Falsches Datumsfornmat")]
[DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}", ApplyFormatInEditMode = true), ]
public DateTime ValidTo
{
     get { return _ValidTo; }
     set { _ValidTo = value; }
}

So in edit-mode the DatePicker is displayed.

But when I pick a a date, a message below the field appears The field "Gültig bis" must be a date.

This Message disappears when I enter the date in yyyy-MM-dd Format, but in ModelState this value is not accepted because of my property-attributes (this is a correct behaviour).

 

The question is, how can I get the Datepicker setup correctly correspondending my property-attributes?
I'm confused beacuse the Date ist picked correctly (in dd.MM.yyyy Format), but the picker itself does not accept it???

 

Greetings,

Denis

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 18 Jun 2015, 09:41 AM
Hello Denis,

The datepicker does not have built-in validation. Assuming that the editor is used for editable widget like the grid, the validation will be performed by the Kendo validator which validates the dates based on the current Kendo culture date formats. In order for the custom format be accepted you should register a culture that includes the used format or override a format in the current culture:
var culture = kendo.culture();
culture.calendar.patterns.d = "dd.MM.yyyy";
or override the validator mvcdate rule:
$.extend(true, kendo.ui.validator, {
    rules: {
        mvcdate: function (input) {
            if (input.is("[data-val-date]") && input.val() != "") {
                var date = kendo.parseDate(input.val(), "dd.MM.yyyy");
                return date !== null;
            }
 
            return true;
        }
    }
});


Regards,
Daniel
Telerik
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
Tags
Date/Time Pickers
Asked by
CAD-OD
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or