forked from PnX-SI/gn_module_monitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prevent form appear if no type-site
- Hide form if btn-list type-site not selected - Add custom error message mat-error if not selected (directive + custom message) WIP: error message is showing up only if not selected after touched . Maybe need to use asyncValidator ? Reviewed-by: andriac [Refs_tickets]: #5 , #6 , #54
- Loading branch information
Showing
11 changed files
with
105 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Component, AfterViewInit, Injector } from '@angular/core'; | ||
import {MatInput } from '@angular/material/input'; | ||
import { MatFormFieldControl,MatFormField } from '@angular/material/form-field'; | ||
|
||
@Component({ | ||
selector: '[matErrorMessages]', | ||
template: '{{ error }}' | ||
}) | ||
export class MatErrorMessagesDirective implements AfterViewInit { | ||
error = ''; | ||
inputRef: MatFormFieldControl<MatInput>; | ||
|
||
constructor(private _inj: Injector) { } | ||
|
||
// Setup all initial tooling | ||
ngAfterViewInit() { | ||
// grab reference to MatFormField directive, where form control is accessible. | ||
let container = this._inj.get(MatFormField); | ||
this.inputRef = container._control; | ||
|
||
// sub to the control's status stream | ||
this.inputRef.ngControl.statusChanges.subscribe(this.updateErrors); | ||
} | ||
|
||
// This grabs a single active error instead of multiple. | ||
private updateErrors = (state: 'VALID' | 'INVALID') => { | ||
if (state === 'INVALID') { | ||
let controlErrors = this.inputRef.ngControl.errors; | ||
const firstError = Object.keys(controlErrors)[0]; | ||
if(firstError === 'required') | ||
this.error = 'Ce champs est requis.'; | ||
|
||
if(firstError === 'minlength') | ||
this.error = 'Vous devez choisir au moins une valeur.'; | ||
} | ||
} | ||
} |