Datepicker does not reset when the form/input is reset

Topic: Datepicker does not reset when the form/input is reset

itkaufmann pro premium priority asked a year ago

The date should be cleared from the datepicker field when I reset its input field. The date will stay in the input field but the value the FormControl returns will be null. I tried to reset the date manually with the viewchild of the datepicker in the typescript code like this but I just the error message TypeError: Cannot read property 'getDay' of null.


<input [mdbDatepicker]="datepicker" type="text" [formControl]="dayInput" class="form-control" id="surcharge-day" placeholder="" (click)=""/> <mdb-datepicker-toggle [mdbDatepicker]="datepicker"></mdb-datepicker-toggle> <mdb-datepicker #datepicker [options]="translationOptions" [inline]="true" [format]="''"></mdb-datepicker>



@Component({ selector: 'app-component', templateUrl: './component.html' }) export class Component implements OnInit {

@ViewChild('datepicker') datepicker; dayInput: FormControl; translationOptions = mdDatepickerTranslationOptions;

constructor(private formBuilder: FormBuilder) {}

ngOnInit(): void { this.addSurchargedayInput = this.formBuilder.control(null, Validators.required); }

add(): void { this.dayInput.reset(); this.datepicker._selectDate(null); } }


Please help me, I really need this to work

Arkadiusz Idzikowski staff commented a year ago

@itkaufmann Thank you for reporting this problem, we will fix that in the next update. I'm afraid there is no easy workaround for now that I could suggest. The component uses private methods to handle form control value changes and you won't be able to modify its internal variables.

Please insert min. 20 characters.


Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.



Specification of the issue
  • User: Pro
  • Premium support: Yes
  • Technology: MDB Angular
  • MDB Version: MDB5 1.0.0-beta5
  • Device: PC
  • Browser: All
  • OS: All
  • Provided sample code: No
  • Provided link: No