ng2-ui / datetime-picker

Angular2 DateTime Picker
https://ng2-ui.github.io/#/datetime-picker
MIT License
121 stars 62 forks source link

the datetime picker cannot update when user modifying value #217

Open wqdjl opened 6 years ago

wqdjl commented 6 years ago

when i input value 2017-09-05 and reopen the datepicker ,the date picker still show the last value ; eg. image

I have the solution, Please update datetime-picker.directive.ts' function ngOnChanges. when user modifying value ,you should be call setInputElDateValue、updateDatepicker eg.

 if (!this.userModifyingValue) {
          setTimeout(() => {
            let dt = this.getDate(date);
            dt.toString = () => NguiDatetime.formatDate(dt, this.dateFormat, this.dateOnly);
            this.ngModel = dt;
            this.inputEl.value = '' + dt;
          })
  } else {
          this.setInputElDateValue(date);
          this.updateDatepicker();
 }

@jiren @lukaselmer @Krisa @boban984

allenhwkim commented 6 years ago

A good idea, I think. Please test and make a PR. Please also consider that user may enter invalid date. 2017-0x-xx

wqdjl commented 6 years ago

you can valid the value , let date: any = new Date(value); if (date == "Invalid Date")

faridabbas-dl commented 6 years ago

in Above fix we prefer the Element value rather then default value .. i.e if value is change by user then popup 'll display from user provided value Otherwise/else default value. Thanks @wqdjl for hint......