0

I m using the little time kendo and found a problem in validating the datepicker.

@using (Ajax.BeginForm("FindByFilter", "Find", new { filter = Model.Filter }, new AjaxOptions { UpdateTargetId = "content", HttpMethod = "GET", InsertionMode = InsertionMode.Replace }))
{
  <div class="demo-section fr" style="width: 340px; margin-top: -2px;">
      <label for="start">Start:</label>
      @(Html.Kendo().DatePickerFor(model => model.Filter.Start)
          .Name("start")
          .Culture("pt-BR")
          .HtmlAttributes(new { style = "width: 140px" })
          .Min(DateTime.Today)
          .Events(e => e.Change("startChange"))
      )

      <label for="end" style="margin-left: 0.5em">End:</label>
      @(Html.Kendo().DatePickerFor(model => model.Filter.End)
          .Name("end")
          .Culture("pt-BR")
          .HtmlAttributes(new { style = "width: 140px" })
          .Min(Model.Filter.Start)
          .Events(e => e.Change("endChange"))
      )
  </div>
  <div>
      <input type="submit" class="button small secondary lupa fr" />
  </div>
}

When I click the submit the datepicker does not accept the format 20/04/2013 only in the format 2013-04-20. I set the culture to pt-BR, but validation is still occurring. Can anyone help?

Renato Vianna
  • 138
  • 2
  • 10
  • Similar question is covered [here][1]. [1]: http://stackoverflow.com/questions/14127305/how-to-validate-a-date-is-in-the-format-yyyy-mm-dd-using-kendo-validator – Petur Subev Apr 17 '13 at 20:30

1 Answers1

1

I seem to remember having exactly the same issue. Like you we changed the culture by using kendo.culture('en-GB') but this didn't resolve the issue. In the end we had to add our own jQuery validator method:

jQuery.validator.addMethod(
    'date',
    function (value, element) {
        if (this.optional(element)) {
            return true;
        };
        var result = false;
        try {
            $.datepicker.parseDate('dd/mm/yy', value);
            result = true;
        } catch (err) {
            result = false;
        }
        return result;
    },
    ''
);
Myles J
  • 2,839
  • 3
  • 25
  • 41
  • Thanks for the feedback Myles. I used your solution, but the problem still continues. Do I need to do something else besides including the script? – Renato Vianna Apr 22 '13 at 12:45
  • 1
    It's a bit hard to tell why it isn't working for you without seeing more code. Where did you add the validator method code? Is it getting called when you edit/save a record? Try adding a Javascript alert test message in the method to see whether it's actually getting called. – Myles J Apr 22 '13 at 13:00