If user enter incorrect date and we have a date in previousDate variable then previousdate should be set on input textbox

57 Views Asked by At
  • I have input textbox in the angular. In this input text user can enter date manually or using datepicker(ngbDatepicker).
  • If user enter valid date then it will assign to previousdate variable.
  • If uset enter incorrect date and we have previous date then previous date should set to inputbox on ui side.

Here resetting date is not working.

current output

Please refer my code changes on github : https://github.com/akshay-yeole/playground

I'm trying to set previousdate to the input textbox in angular if previous date exists then only.

1

There are 1 best solutions below

0
Eliseo On

It's only add an If in your blur

  onBlur(event: any) {
    const date = event?.target.value;
    this.isValidDate = this.validateDate(date);
    if (this.isValidDate) {
      this.previousDate.value = this.model.value ?? '';
    } else {
      if (this.previousDate.value) {
        this.model.value = this.previousDate.value ?? '';
        this.isValidDate = true;
        this.cd.markForCheck();
      }
    }
  }

NOTE: I forked your code in this stackblitz (It's more easy "play" using stackblitz than github)