DatePicker value in Grid Inline editing

5 posts, 0 answers
  1. Raja
    Raja avatar
    43 posts
    Member since:
    Oct 2013

    Posted 02 Feb Link to this post

    I have two Date Pickers inside a grid "Start Date" and "End Date".I am trying to validate these dates on edit and want to show only one validation message any time. Everything works fine except one scenario.

    Steps that creates a problem:

    1. Select a date for Start Date (ex. 1/1/2015) and select a date for End Date (ex. 2/1/2015). Everything is fine. I can save the record successfully.

    2. Now change the  Start date to 3/1/2015 and validation popsup as expected. Change the end date to 4/1/2015 so that its greater then Start Date. Validation message disappears as expected.

    3. Now if I try to Save, I get 1/1/2015 as the value on my server side code, not 3/1/2015. 

         $("StartDate").value() -- this has 3/1/215

         $("#grid").data("kendoGrid").dataSource.view() - this has startdate as 1/1/2015 which is wrong.

    If I don't have the validation, everything works fine. What is causing this behavior? Please help.

    My validation logic:

    dateValidation: function(input){
       if ((input.is("[name='StartDate']") || input.is("[name='EndDate']")) && input.val() != "")
       {
         $("div.k-invalid-msg[data-for='StartDate']").hide();
         $("div.k-invalid-msg[data-for='EndDate']").hide();
     
         var startDate = new Date($("#StartDate").val());
         var endDate = new Date($("#EndDate").val());
     
         if (endDate < startDate)
           return false;
         else
           return true;
       }
       return true;
    }

  2. Raja
    Raja avatar
    43 posts
    Member since:
    Oct 2013

    Posted 04 Feb in reply to Raja Link to this post

    As I have not received any response on this thread, i have created a support ticket.
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 04 Feb Link to this post

    Hello Raja,

     

    The reason for this behavior is that when the validation fails the model is not updated with new value. So basically the model remains its old value. When the end date is changed it performs the validation, but it takes the values in the input field and compare them. 

     

    My suggestion is when the end date is changed to trigger "change" of input of the start data. In this case the validation will be fired one more time and if the validation passes the model will update properly. 

     

    Regards,
    Boyan Dimitrov
    Telerik
    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
  5. Raja
    Raja avatar
    43 posts
    Member since:
    Oct 2013

    Posted 04 Feb in reply to Boyan Dimitrov Link to this post

    Thank you for your response. But this can happen for StartDate or EndDate and if I trigger change for other element I may end up going to infinite loop.

     

    Is there a way to update the model manually?

  6. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 08 Feb Link to this post

    Hello Raja,

     

    Indeed the validation is bound to the input element, so you can change the model using its set method. 

     

    In order to get the model instance you can: 

     

      1. Get the row that is being edited. The row has a "k-grid-edit-row" class applied. 

      2. Retrieve its uid value from the table row and use getByUid method of the Kendo UI DataSource. 

     

    Regards,
    Boyan Dimitrov
    Telerik
    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready