Start date and end date validation

2 posts, 0 answers
  1. DHHS
    DHHS avatar
    59 posts
    Member since:
    Mar 2015

    Posted 16 Jul 2015 Link to this post

    I have a start date and end date validation where user can not choose a end date previous that of start date. I have written code on datepicker change event and it is working fine. But if i have already have value in the start date from the model and didnt pick from the datepicker, on end date change event the value of start date is null.
    View Code/ works fine if the value is picked from datepicker
        <div class="form-group">
              @Html.LabelFor(model => model.StartDate, htmlAttributes: new { @class = "control-label col-md-2 k-label" })
              <div class="col-md-10">    
                  @(Html.Kendo().DatePicker().Name("StartDate").Value(Model.StartDate).HtmlAttributes(new { style = "width:250px", onkeydown = "javascript:return false;", required = "required" }).Events(e => e.Change("startChange"))) 
                  @Html.ValidationMessageFor(model => model.StartDate, "", new { @class = "text-danger" })
          <div class="form-group">
              @Html.LabelFor(model => model.EndDate, htmlAttributes: new { @class = "control-label col-md-2 k-label" })
              <div class="col-md-10">
                  @(Html.Kendo().DatePicker().Name("EndDate").Value(Model.EndDate).HtmlAttributes(new { style = "width:250px", onkeydown = "javascript:return false;" }).Events(e => e.Change("endChange")))               
                  @Html.ValidationMessageFor(model => model.EndDate, "", new { @class = "text-danger" })
    function startChange() {    
          var endPicker = $("#EndDate").data("kendoDatePicker"),
              startDate = this.value();
          if (startDate) {
              startDate = new Date(startDate);
              startDate.setDate(startDate.getDate() + 1);
      function endChange() {      
          var startPicker = $("#StartDate").data("kendoDatePicker"),
              endDate = this.value();      
          if (endDate) {
              endDate = new Date(endDate);
              endDate.setDate(endDate.getDate() - 1);
  2. Georgi Krustev
    Georgi Krustev avatar
    3687 posts

    Posted 20 Jul 2015 Link to this post


    The described behavior is not expected. The "StartDate" widget should have an initial value if it was set from the Model. I suppose that in this case, the widget's max value is set to a lower date than the current selected. In this case the value of the widget will be adjusted, but it will not be "null". Could you check and if possible modify the attached test project? This will help us to see the issue locally and find a feasible solution faster.

    One thing that come to my mind is that you can set the Min/Max values of the widgets initially too:

    Georgi Krustev
    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 AJAX banner
Back to Top