DatePicker validates differently w/o value

1 posts, 0 answers
  1. Ivan
    Ivan avatar
    3 posts
    Member since:
    Jun 2009

    Posted 26 Apr 2012 Link to this post

    I have the following code in my page:

    <div id="myform">
       <input type="date" id="myDate" name="myDate" data-date-msg="Invalid date" data-bind="value: myField" />
       <br />
       <button id="show" type="button">Show selected</button>
       <button id="clear" type="button">Clear</button>
    </div>
     
    <script>
        $(document).ready(function ()
        {
            var model = kendo.observable({ myField: new Date() });
     
            $("#myDate").kendoDatePicker();
            kendo.bind($("#myDate"), model);
     
            var validatable = $("#myform").kendoValidator().data("kendoValidator");
            $("#show").click(function ()
            {
                if (validatable.validate())
                {
                    alert('Selected: ' + model.get("myField"));
                }
            });
     
            $("#clear").click(function ()
            {
            model.set('myField', null);
            });
        });
    </script>

    Test cases:
    1. Reload page, click "Clear", enter "abc" and click "Show selected" - it correctly displays the "Invalid date" and no alert is fired.
    2. Reload page, enter "abc" in the DatePicker and click "Show selected" - it validates as true and shows an alert dialog.

    Is there a way to make case 2 work the same as 1?
Back to Top