kendo-datepicker clear the value by code

1 Answer 431 Views
DatePicker
Maurizio
Top achievements
Rank 1
Iron
Maurizio asked on 01 Feb 2024, 05:44 PM

Hello,
we work in angular and typescript.

I need to make a button who reset all control in the form to empty value.

How I can clear the value of kendo-datepicker ?

When we load the the form the kendo-datekiper is blank (like the sampe https://www.telerik.com/kendo-angular-ui/components/dateinputs/datepicker/)

A user select a date. If the user clear manually the date all work.

I need the code for reset the value kendo-datepicker to  "bank" ? null? undefined? 

I have tried woth the binding of the value properties.

variable:

dt_value!: Date;

<kendo-datepicker [(value)] = "dt_value" > </kendo-datepicker>

But if I set variable dt_value to undefined I receive an error.

Thanks for any help.

LSo

1 Answer, 1 is accepted

Sort by
0
Zornitsa
Telerik team
answered on 06 Feb 2024, 11:46 AM

Hello Maurizio,

Indeed, the components in our Date Inputs package do not support having null values at present. However, our team is considering improving our DateInputs package for the value to accept `null` and the following thread can be tracked on this matter:

For the time being, you could check out the workaround shared in the comments, which suggests using $any() to disable the type check:

<kendo-datepicker [value]="$any(value)"></kendo-datepicker>

Alternatively, since I assume that the DatePicker is used in a form as it is mentioned in the ticket, I would suggest setting the value of the corresponding FormControl to null, instead of the component value itself:

<form [formGroup]="myForm">
     <label>
          Select Birthdate:
          <kendo-datepicker formControlName="birthDate"></kendo-datepicker>
      </label>
</form>
public myForm: FormGroup = new FormGroup({
    birthDate: new FormControl(null), 
});

 I am also sharing a StackBlitz example for a demonstration of the second approach:

Hope that the provided information is helpful for your scenario. I remain at your disposal in case of any further questions.

Regards,
Zornitsa
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
Tags
DatePicker
Asked by
Maurizio
Top achievements
Rank 1
Iron
Answers by
Zornitsa
Telerik team
Share this question
or