MCPcopy Create free account
hub / github.com/angular/components / _onInput

Function _onInput

src/material/datepicker/datepicker-input-base.ts:326–357  ·  view source on GitHub ↗
(event: Event)

Source from the content-addressed store, hash-verified

324 }
325
326 _onInput(event: Event) {
327 const value = (event.target as HTMLInputElement).value;
328 const lastValueWasValid = this._lastValueValid;
329 let date = this._dateAdapter.parse(value, this._dateFormats.parse.dateInput);
330 this._lastValueValid = this._isValidValue(date);
331 date = this._dateAdapter.getValidDateOrNull(date);
332 const hasChanged = !this._dateAdapter.sameDate(date, this.value);
333
334 // We need to fire the CVA change event for all
335 // nulls, otherwise the validators won't run.
336 if (!date || hasChanged) {
337 this._cvaOnChange(date);
338 } else {
339 // Call the CVA change handler for invalid values
340 // since this is what marks the control as dirty.
341 if (value && !this.value) {
342 this._cvaOnChange(date);
343 }
344 }
345
346 // Re-run the validators if the parse state changed while the value stayed the same.
347 // This also covers going from one null to another (e.g. clearing an unparseable value),
348 // because signal forms skip value writes that don't change the value.
349 if (!hasChanged && lastValueWasValid !== this._lastValueValid) {
350 this._validatorOnChange();
351 }
352
353 if (hasChanged) {
354 this._assignValue(date);
355 this.dateInput.emit(new MatDatepickerInputEvent(this, this._elementRef.nativeElement));
356 }
357 }
358
359 _onChange() {
360 this.dateChange.emit(new MatDatepickerInputEvent(this, this._elementRef.nativeElement));

Callers

nothing calls this directly

Calls 2

_assignValueMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected