This is a migrated thread and some comments may be shown as answers.
Datepicker Client API given old value in custom client side validator
4 Answers 29 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Niels
Top achievements
Rank 1
Niels asked on 24 Nov 2010, 01:48 PM
Hi,

I've implemented een custom validator for MVC 2 to validate if property of type DateTime is a workday. In the client side validation script I use the datapickers client side API, Problem is that the value() method gives back the old selected value not the new one. It looks like te validation is triggered before the new date is available.

Is there a way to get the newly selected value?

Thanks,

Niels

ps. the client side script looks like:

if (jQuery.validator) {
    jQuery.validator.addMethod("workday", function (value, element, params) {
  
        var chosenDate = new Date(value);
  
        // check if element is datepicker
        var obj = $(element.parentElement.parentElement)
        if (obj.data() && obj.data('tDatePicker')) {
            chosenDate = obj.data('tDatePicker').value();
            obj.data('tDatePicker').hidePopup();
        }
  
        var isWorkday = chosenDate.getDay() > 0 && chosenDate.getDay() < 6;
  
        return isWorkday;
    });
}



4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 24 Nov 2010, 05:06 PM
Hello Niels,

This is not a known issue. Could you please send us a simple test project which reproduces the described problem. Thus I will be able to review it locally and advice you further.

Regards,
Georgi Krustev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Niels
Top achievements
Rank 1
answered on 24 Nov 2010, 09:45 PM
Hello Georgi,

I attached a test project. When you debug the javascript in WorkdayValidation.js in the scripts folder you will see that while the code runs the selected value is not changed yet.

Hope you can help me with this. Am I doing something wrong?

Kind Regards,

Niels
0
Georgi Krustev
Telerik team
answered on 25 Nov 2010, 10:26 AM
Hello Niels,

Thank you for the test project.

Unfortunately I was not able to reproduce depicted issue. DatePicker UI component returns correctly selected date. Check this screencast and let me know if I am missing something.

Regards,
Georgi Krustev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Niels
Top achievements
Rank 1
answered on 26 Nov 2010, 08:56 AM
Hello Georgi,

Thanks for looking into my problem. This is strange, when I play the exact scenario you recorded the first step (e.g. select a saturday) will result in a validation error after submit. The second step (select a workdag) does not give the desired result. The fact that first a non workday is selected is not the cause of the problem because selecting a workday on the first step results in the same behavior, you simply cannot choose another day!

Did some more debugging and did find the problem. Earlier this week I had a problem of the popup not hiding when a workday was selected. I solved this by hiding the popup from the validation javascript code. In the end this was causing the "old date" problem. The problem with the popup hide is gone. I'm not sure why but I think it has something to do

Why it did work on your side I cannot explain.

Thanks for your help on this.
Tags
Date/Time Pickers
Asked by
Niels
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Niels
Top achievements
Rank 1
Share this question
or