This is a migrated thread and some comments may be shown as answers.

DatePicker value in Grid Inline editing

4 Answers 370 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raja
Top achievements
Rank 1
Raja asked on 02 Feb 2016, 07:54 PM

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;
}

4 Answers, 1 is accepted

Sort by
0
Raja
Top achievements
Rank 1
answered on 04 Feb 2016, 05:07 PM
As I have not received any response on this thread, i have created a support ticket.
0
Boyan Dimitrov
Telerik team
answered on 04 Feb 2016, 05:09 PM

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
0
Raja
Top achievements
Rank 1
answered on 04 Feb 2016, 05:15 PM

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?

0
Boyan Dimitrov
Telerik team
answered on 08 Feb 2016, 03:55 PM

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
Tags
Grid
Asked by
Raja
Top achievements
Rank 1
Answers by
Raja
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or