ngx-ode-ui 4.8.0-dev.0develop-b2school.13 → 4.8.0-dev.0develop-b2school.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, forwardRef, EventEmitter, Component, ViewChild, Input, Output, HostBinding, Directive, Pipe, TemplateRef, ContentChild, ChangeDetectionStrategy, HostListener, ContentChildren, Injector, NgModule } from '@angular/core';
3
- import { throwError, Observable, Subject } from 'rxjs';
3
+ import { throwError, Observable, Subject, fromEvent } from 'rxjs';
4
4
  import { OdeComponent } from 'ngx-ode-core';
5
+ import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
5
6
  import * as i2 from '@angular/forms';
6
7
  import { NG_VALUE_ACCESSOR, NgModel, FormsModule } from '@angular/forms';
7
8
  import Flatpickr from 'flatpickr';
@@ -12,7 +13,6 @@ import * as i2$1 from 'ngx-ode-sijil';
12
13
  import { NgxOdeSijilModule } from 'ngx-ode-sijil';
13
14
  import * as i2$2 from 'ngx-infinite-scroll';
14
15
  import { InfiniteScrollModule } from 'ngx-infinite-scroll';
15
- import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
16
16
 
17
17
  class DynamicModuleImportsService {
18
18
  constructor() {
@@ -202,6 +202,7 @@ class DatepickerComponent extends OdeComponent {
202
202
  this.changeDate = new EventEmitter();
203
203
  this.onChangeCallback = NOOP;
204
204
  this.onTouchedCallback = NOOP;
205
+ this.onInputChangeObserver = null;
205
206
  }
206
207
  get value() {
207
208
  return this.innerValue;
@@ -250,28 +251,48 @@ class DatepickerComponent extends OdeComponent {
250
251
  altInput: !this.disabled,
251
252
  altFormat: 'd/m/Y',
252
253
  dateFormat: 'Y-m-d',
253
- allowInput: false,
254
+ allowInput: true,
254
255
  enableTime: this.enableTime,
255
256
  minDate: this.minDate,
256
257
  maxDate: this.maxDate,
257
258
  clickOpens: false,
258
259
  wrap: true,
259
- locale: datePickerLocale
260
+ locale: datePickerLocale,
261
+ onChange: (selectedDates, dateStr) => {
262
+ this.value = dateStr;
263
+ },
264
+ onClose: () => {
265
+ this.onTouchedCallback();
266
+ }
260
267
  };
261
268
  this.datePickerInst = new Flatpickr(this.datePickerElement.nativeElement, options);
262
269
  if (!this.disabled) {
270
+ // Add click handler for the alt input
263
271
  this.datePickerInst.altInput.addEventListener('click', e => {
264
272
  if (!this.readonly) {
265
273
  this.datePickerInst.toggle();
266
274
  }
267
275
  });
276
+ // Add input handler for manual entry with debounce
277
+ this.onInputChangeObserver = fromEvent(this.datePickerInst.altInput, 'input')
278
+ .pipe(debounceTime(300))
279
+ .subscribe(() => {
280
+ // when user input a date manually, we try to parse it and set it as selected date
281
+ const inputDate = this.datePickerInst.parseDate(this.datePickerInst.altInput.value, options.altFormat);
282
+ if (inputDate) {
283
+ this.datePickerInst.setDate(inputDate, true);
284
+ }
285
+ });
268
286
  }
269
- // Force updating the date input readonly attribute :
287
+ // Force updating the date input readonly attribute
270
288
  this.readonly = this._readonly;
271
289
  }
272
290
  ngOnDestroy() {
273
291
  super.ngOnDestroy();
274
292
  this.datePickerInst.destroy();
293
+ if (this.onInputChangeObserver) {
294
+ this.onInputChangeObserver.unsubscribe();
295
+ }
275
296
  }
276
297
  writeValue(value) {
277
298
  if (value !== this.innerValue && this.datePickerInst) {