0

I am using a kendo datetimepicker. When user opens the calender and select any date I need to check for some other dates, ie need to run validations if the date is wrong then prevent the new date from filling the date picker and keep the old value, otherwise allow datepicker to change value. I tried with event.preventDeafult , but unfortunatly it is not working..

Is there any way to acheceive this?

Here is the fiddle enter link description here

Any help is appreciated.

Example fiddle here

   $("#datePicker").kendoDatePicker({

    change:function(event){ alert(1); 
                      // some validations here
                      event.preventDeafult();  }
  });
Shebin Mathew
  • 320
  • 1
  • 7
  • 18
  • Did you try this: http://stackoverflow.com/questions/16151446/kendo-ui-datepicker-getting-the-previous-value/16153238#16153238 – OnaBai Sep 16 '14 at 12:45
  • Nice its working and I wanted this one. By the way where can i get the documentation for prev – Shebin Mathew Sep 16 '14 at 18:23
  • There is no documentation because this is an extension that I've proposed. JavaScript allows you this: you can easily extend adding your own fields. So the trick is add it, then keep updating it. – OnaBai Sep 16 '14 at 20:57

2 Answers2

1

Go through this answer. May any lines help you to solve your problem. You can simply assign like this.

$("#datepicker").kendoDatePicker({
    change: function () {
        // some validations here
        var i = 0;
        var prev = "9/12/2014";
        var date = kendo.toString(this.value(), 'd');
        if (i == 0) {
            $("#datepicker").data("kendoDatePicker").value(prev);
        }
    },
    close: onClose,
    open: onOpen
});

Updated Answer :

var date;
$(function () {
    date = $("#datepicker").data("kendoDatePicker").value();
    $("#datepicker").kendoDatePicker({
        change: function () {
            // some validations here
            var i = 0;
            var prev = date;
            if (i == 0) {
                $("#datepicker").data("kendoDatePicker").value(prev);
            }

        },
        close: onClose,
        open: onOpen,
    });

})
Magicprog.fr
  • 4,072
  • 4
  • 26
  • 35
Raju S Nair
  • 333
  • 2
  • 5
  • 17
  • I want the previous value to be dynamic, ie the value just before the change event, if the user selcts wrong date then alert has to come and say error, and the old value has to be kept as it is in case of error – Shebin Mathew Sep 16 '14 at 05:35
0

I've used read only in the past to do this.

   var endDate = $("#endDate").data("kendoDatePicker");
       endDate.readonly();
CSharper
  • 5,420
  • 6
  • 28
  • 54