Error clear 'day month year' when using .DateInput(true)

1 Answer 298 Views
Date/Time Pickers
Miro
Top achievements
Rank 1
Iron
Iron
Miro asked on 23 Jun 2021, 04:29 AM

In picture 1: pic 1: ActualStartDate & ActualFinishDate allow null-able value.

In Picture 2: because their types allow nullable so the values of Actual Start Date & Actual Finish Date must be empty. Because I am using .DateInput(true) in the controls so now they have value 'day month year'. 


Currently, I am getting an error model state is invalid, Could you help me how to clear 'day month year' when using .DateInput(true)

1 Answer, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 25 Jun 2021, 03:35 PM

Hello Miro,

Thank you for the shared screenshots.

I would suggest binding an event handler to the "submit" event of the form and setting the values of the actual inputs to "null":

$("form").on("submit", function (e) {
        e.preventDefault();
        $("#ActualStartDate").val(null);
        $("#ActualFinishDate").val(null);
        $("form").off("submit");
        $(this).submit(); 
});

Would you give this approach a try and let me know if it works properly at your end?

 

Regards, Mihaela Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Miro
Top achievements
Rank 1
Iron
Iron
commented on 28 Jun 2021, 03:08 AM

First: we don’t use event submit
Second: why we set these value always to null because at some point they will have value
It will be ok if we set it to .DateInput(false), But if we set to false, mean user can input anything to DatePicker control. The issue and the screen shot attached related to the error, that when we set to true which is what we need, we get an error or wrong value.
Mihaela
Telerik team
commented on 30 Jun 2021, 12:16 PM

You could check the value of both DatePickers and set "null" only if there are no selected dates:

$("form").on("submit", function (e) {
        e.preventDefault();
        var submittedStartDate = $("#ActualStartDate").data("kendoDatePicker").value();
        var submittedFinishDate = $("#ActualFinishDate").data("kendoDatePicker").value();
        if(submittedStartDate == null) {
            $("#ActualStartDate").val(null);
        }
        if(submittedFinishDate == null) {
            $("#ActualFinishDate").val(null);
        }
        $("form").off("submit");
        $(this).submit(); 
});

Would you please explain how you send the submitted data to the server?

Thank you for your cooperation.

 

Tags
Date/Time Pickers
Asked by
Miro
Top achievements
Rank 1
Iron
Iron
Answers by
Mihaela
Telerik team
Share this question
or