Skip to content

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

Merged
kara merged 1 commit into
angular:masterfrom
crisbeto:select-error-state-matcher-resubmit
Oct 4, 2017
Merged

feat(select): add support for custom error state matcher#7443
kara merged 1 commit into
angular:masterfrom
crisbeto:select-error-state-matcher-resubmit

Conversation

@crisbeto

@crisbetocrisbeto commented Sep 30, 2017

Copy link
Copy Markdown
Member
  • 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

@googlebotgooglebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 30, 2017
@crisbeto
crisbetoforce-pushed the select-error-state-matcher-resubmit branch from dfeaa7f to ee63ccdCompareSeptember 30, 2017 12:48
Comment threadsrc/lib/input/input.ts Outdated
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
Copy Markdown
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
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done.

Comment threadsrc/lib/select/select.ts Outdated
const matcher = this.errorStateMatcher || this._defaultErrorStateMatcher;

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

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done.

@crisbeto
crisbetoforce-pushed the select-error-state-matcher-resubmit branch from ee63ccd to 21ec8eeCompareSeptember 30, 2017 17:23
Comment threadsrc/lib/core/error/error-options.ts Outdated
@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
Copy Markdown
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
Copy Markdown
MemberAuthor

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.

Comment threadsrc/lib/core/error/error-options.ts Outdated
@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
Copy Markdown
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
Copy Markdown
Contributor

fixes #7419

@crisbeto
crisbetoforce-pushed the select-error-state-matcher-resubmit branch from 21ec8ee to de279dcCompareSeptember 30, 2017 18:04
@crisbeto

Copy link
Copy Markdown
MemberAuthor

Addressed the feedback @mmalerba.

@mmalerbammalerba 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
Copy Markdown
Contributor

Breaking changes comment for switching from function to ErrorStateMatcher class?

@kara

kara commented Oct 3, 2017

Copy link
Copy Markdown
Contributor

@crisbeto Rebase?

@karakara assigned crisbeto and unassigned mmalerbaOct 3, 2017
@karakara added pr: needs rebase and removed action: merge The PR is ready for merge by the caretaker labels Oct 3, 2017
@crisbeto
crisbetoforce-pushed the select-error-state-matcher-resubmit branch from de279dc to ad38bb9CompareOctober 3, 2017 19:33
@crisbetocrisbeto added action: merge The PR is ready for merge by the caretaker and removed pr: needs rebase labels Oct 3, 2017
@crisbeto

Copy link
Copy Markdown
MemberAuthor

Rebased.

@karakara 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.
Fixesangular#7419.
@crisbeto
crisbetoforce-pushed the select-error-state-matcher-resubmit branch from ad38bb9 to a3c364cCompareOctober 4, 2017 17:33
@crisbetocrisbeto 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:masterOct 4, 2017
@angular-automatic-lock-bot

Copy link
Copy Markdown

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-botangular-automatic-lock-botBot locked and limited conversation to collaborators Sep 7, 2019
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: mergeThe PR is ready for merge by the caretakercla: yesPR 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

@crisbeto@mmalerba@willshowell@kara@googlebot