Skip to content
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

feat(select): add support for custom error state matcher #7443

Merged
merged 1 commit into from
Oct 4, 2017

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Sep 30, 2017

  • Allows for the select's error state matcher to be overwritten through an @Input.
  • Switches MatSelect over to use the same global provider for its error state as MatInput.

Note: This is a resubmit of #6147 that works with our latest setup and excludes a few changes.

Fixes #7419

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 30, 2017
@crisbeto crisbeto force-pushed the select-error-state-matcher-resubmit branch from dfeaa7f to ee63ccd Compare September 30, 2017 12:48
@@ -232,7 +223,8 @@ export class MatInput implements MatFormFieldControl<any>, OnChanges, OnDestroy,
const oldState = this.errorState;
const ngControl = this.ngControl;
const parent = this._parentFormGroup || this._parentForm;
const newState = ngControl && this.errorStateMatcher(ngControl.control as FormControl, parent);
const matcher = this.errorStateMatcher || this._defaultErrorStateMatcher;
const newState = ngControl && matcher.isErrorState(ngControl, parent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isErrorState accepts null ngControl, so no need to check here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


return !!(isInvalid && (isTouched || isSubmitted));
return ngControl && matcher.isErrorState(ngControl, parent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, no need to check that ngControl is non-null

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@crisbeto crisbeto force-pushed the select-error-state-matcher-resubmit branch from ee63ccd to 21ec8ee Compare September 30, 2017 17:23
@Injectable()
export class ShowOnDirtyErrorStateMatcher implements ErrorStateMatcher {
isErrorState(control: NgControl | null, form: FormGroupDirective | NgForm | null): boolean {
return control ? !!(control.invalid && (control.dirty || (form && form.submitted))) : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this work? return !!(control && control.invalid && (control.dirty || form && form.submitted))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should, I don't remember why we went with the ternary initially.

@Injectable()
export class ErrorStateMatcher {
isErrorState(control: NgControl | null, form: FormGroupDirective | NgForm | null): boolean {
return control ? !!(control.invalid && (control.touched || (form && form.submitted))) : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return !!(control && control.invalid && (control.touched || form && form.submitted))

@mmalerba
Copy link
Contributor

fixes #7419

@crisbeto crisbeto force-pushed the select-error-state-matcher-resubmit branch from 21ec8ee to de279dc Compare September 30, 2017 18:04
@crisbeto
Copy link
Member Author

Addressed the feedback @mmalerba.

@mmalerba mmalerba added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Oct 1, 2017
@willshowell
Copy link
Contributor

Breaking changes comment for switching from function to ErrorStateMatcher class?

@kara
Copy link
Contributor

kara commented Oct 3, 2017

@crisbeto Rebase?

@kara kara assigned crisbeto and unassigned mmalerba Oct 3, 2017
@kara kara added pr: needs rebase and removed action: merge The PR is ready for merge by the caretaker labels Oct 3, 2017
@crisbeto crisbeto force-pushed the select-error-state-matcher-resubmit branch from de279dc to ad38bb9 Compare October 3, 2017 19:33
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed pr: needs rebase labels Oct 3, 2017
@crisbeto
Copy link
Member Author

crisbeto commented Oct 3, 2017

Rebased.

@kara kara added pr: needs rebase and removed action: merge The PR is ready for merge by the caretaker labels Oct 3, 2017
* Allows for the select's error state matcher to be overwritten through an `@Input`.
* Switches `MatSelect` over to use the same global provider for its error state as `MatInput`.

**Note:** This is a resubmit of angular#6147 that works with our latest setup and excludes a few changes.

Fixes angular#7419.
@crisbeto crisbeto force-pushed the select-error-state-matcher-resubmit branch from ad38bb9 to a3c364c Compare October 4, 2017 17:33
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed pr: needs rebase labels Oct 4, 2017
@kara kara merged commit a774688 into angular:master Oct 4, 2017
@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 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MdInput] Cannot read property 'invalid' of null
5 participants