Skip to content

Commit

Permalink
fix(ngDoCheck): check error on markAllAsTouched()
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Balet committed Apr 15, 2024
1 parent 6a4038b commit e4d0258
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mat-birthday-input",
"version": "17.3.0",
"version": "17.4.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-mat-birthday-input-tester/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<title>ngxBackButtonTester</title>
<title>ngxMatBirthdayInput</title>
<base href="/" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-mat-birthday-input/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mat-birthday-input",
"version": "17.3.0",
"version": "17.4.0",
"author": {
"name": "Raphaël Balet",
"email": "raphael.balet@outlook.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,17 @@ export class NgxMatBirthdayInputComponent

ngDoCheck(): void {
if (this.ngControl) {
const isInvalide = this.errorStateMatcher.isErrorState(
this.ngControl.control,
this._parentForm,
)
const oldState = this.errorState
const newState = this.errorStateMatcher.isErrorState(this.ngControl.control, this._parentForm)

this.errorState =
(isInvalide && !this.ngControl.control?.value) || (!this.focused ? isInvalide : false)
(newState && (!this.ngControl.control?.value || this.ngControl.control?.touched)) ||
(!this.focused ? newState : false)

if (oldState !== newState) {
this.errorState = newState
this.stateChanges.next()
}
}
}

Expand Down Expand Up @@ -263,10 +267,12 @@ export class NgxMatBirthdayInputComponent
}

registerOnChange(fn: any): void {
console.log('registerOnChange')
this.propagateChange = fn
}

registerOnTouched(fn: any): void {
console.log('registerOnTouched')
this.onTouched = fn
}

Expand All @@ -277,6 +283,7 @@ export class NgxMatBirthdayInputComponent
}

writeValue(value: any): void {
console.log('writeValue')
this._updateItemForm(value)

// Value is set from outside using setValue()
Expand Down

0 comments on commit e4d0258

Please sign in to comment.