Validation message is not working properly for datetimepicker?

你离开我真会死。 提交于 2019-12-12 13:17:23

问题


Here issue is to validate the datetimepicker and reset the values after page load.

In pageload validation is working properly but datetimepickers values are not reset.

After pageload having the both the issues values are not reset and validation is not working.

Here is the fiddle: http://jsfiddle.net/XHW3w/6/

enter code here:$("#filter-msg").kendoWindow({
  modal: true,
  visible: false
    });
 $("#reset").click(function () {
 $("#datetimepicker1").val('');
 $("#datetimepicker2").val('');
 });

$("#datetimepicker1").kendoDatePicker({});
 $("#datetimepicker2").kendoDatePicker({}); 

Above is my code.


回答1:


In the filter function the value for mindate and maxdate is coming back as null. This is because .data() has not stored the updated value from the datepicker.

I have updated your code to use the value of the datepickers as shown in the fiddle.

http://jsfiddle.net/XHW3w/9/

$("#filter").on("click", function () {
   var mindate = $('#datetimepicker1').val();  // uses the val method
   var maxdate = $('#datetimepicker2').val();  // uses the val method

   var product = $("#products").data("kendoDropDownList").value();
   var order = $("#orders").data("kendoDropDownList").value();

    if (!mindate || !maxdate || !product || !order) {
      var content = "";
       if (!mindate) 
        content += "<div class=\"k-error-colored\">mindate is not defined!</div>";
       if (!maxdate) 
        content += "<div class=\"k-error-colored\">maxdate is not defined!</div>";
       if (!product) 
        content += "<div class=\"k-error-colored\">product is not defined!</div>";
       if (!order) 
        content += "<div class=\"k-error-colored\">order is not defined!</div>";

    $("#filter-msg").data("kendoWindow")
        .content(content)
        .center()
        .open();
    return false;
    }
});


来源:https://stackoverflow.com/questions/16165681/validation-message-is-not-working-properly-for-datetimepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!