Skip to content

mat-error can not be displayed when i compare password and confirmPassword #14118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pierre03 opened this issue Nov 13, 2018 · 5 comments
Closed

Comments

@pierre03
Copy link

Bug, feature request, or proposal:

I tried to compare the value of two fields in the form, but it doesn't work with mat-error.
When i set a password, i want to display two error messages under the two input component or display at least the error message under the empty component.

Here is one of the input component, another one is coded with the same code.

HTML:

*****
<mat-error *ngIf="form.errors.mismatch">
mismatch error

TYPESCRIPT:

const form = new FormGroup({
password: new FormControl('', Validators.minLength(2)),
passwordConfirm: new FormControl('', Validators.minLength(2)),
}, passwordMatchValidator);

function passwordMatchValidator(g: FormGroup) {
return g.get('password').value === g.get('passwordConfirm').value
? null : {'mismatch': true};
}

What is the expected behavior?

I want to display the error after the input

What is the current behavior?

No error displayed

What are the steps to reproduce?

Providing a StackBlitz reproduction is the best way to share your issue.

StackBlitz starter: https://goo.gl/wwnhMV

What is the use-case or motivation for changing an existing behavior?

I want to compare the password, and display the error message after each input component
It works when i use the <div *ngIf="hasError()"> to dislpay the error message, but not with mat-error.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular V5.0.3
Material: V5.0.0-rc.1

Is there anything else we should know?

@willshowell
Copy link
Contributor

@pierre03
Copy link
Author

Hello,
Thank you for your reply, in fact, i have already added the ErrorStateMatcher="myMatcher" for these two fields, it works well to verify the "required" test (The field should not be empty when "dirty" or "touched"), then i need to compare the two fields' value.
I have also tried to create a function with the two fields' value as parameters, but it doesn't work when i change the password value, the function can not be trigged with the new value.

exemple works without mat-error on stackoverflow

Can you tell me how to do it with mat-error, please?

@willshowell
Copy link
Contributor

@josephperrott
Copy link
Member

Please keep GitHub issues for bug reports / feature requests. Better avenues for troubleshooting / questions are stack overflow, gitter, mailing list, etc.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants