Format-issues using DatePicker

2 posts, 0 answers
  1. CAD-OD
    CAD-OD avatar
    2 posts
    Member since:
    Mar 2015

    Posted 16 Jun 2015 Link to this post

    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

  2. Daniel
    Admin
    Daniel avatar
    2118 posts

    Posted 18 Jun 2015 Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top