-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[form-field] add md-error-container directive to content projection #6625
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
Comments
Good idea, however it still fails if you want to abstract some complex logic in a separated component, like this:
form-validation.component.ts:
|
Good point. I suppose it could also work as an attribute? <md-form-field>
<input mdInput>
<app-form-validation md-error-container [control]="myCtrl"></app-form-validation>
</md-form-field> <md-form-field>
<input mdInput>
<ng-container md-error-container *ngFor="let error of allErrors">
<md-error *ngIf="showError(error)">{{error.message}}</md-error>
</ng-container>
</md-form-field> |
@willshowell, I do not remember where I found it, but you can use, as an acceptable workaround, the <md-form-field>
<input mdInput>
<ng-container *ngFor="let error of allErrors" ngProjectAs="md-error">
<md-error *ngIf="showError(error)">{{error.message}}</md-error>
</ng-container>
</md-form-field> I will look for the reference where I got this. Edited: just found it => https://medium.com/claritydesignsystem/ng-content-the-hidden-docs-96a29d70d11b Plunk: http://plnkr.co/edit/pmJbQMFMtNqFEbLRZAdP?p=preview Anyway, it doesn't look like this so not-documented |
Whoa thank you @julianobrasil! I've skimmed that article a half dozen times but somehow missed it each time. Personally, I think utilizing @rafaelss95 what do you think? That should also solve your logic encapsulation use case, right? |
@julianobrasil @willshowell It's an awesome solution for simple cases, but for the case that I described (unless I'm missing something here) it still fails. |
@rafaelss95, I think you are right. The using of |
@julianobrasil At the first, I thought the same, however the surprise (at least for me) came when I realized that it worked even wrapped by two (or more) "tags". Note that it's doesn't matter if you use |
I think there may be a bug in core. This shows all 4 errors (3 from <md-form-field>
<input mdInput [formControl]="myControl" required>
<app-form-validation ngProjectAs="md-error"></app-form-validation>
<ng-container ngProjectAs="md-error">
<md-error>This field is required</md-error>
</ng-container>
</md-form-field> http://plnkr.co/edit/2VqnymNAkTzRCOyK0dT1?p=preview ...while (as demoed), this doesn't show any: <md-form-field>
<input mdInput [formControl]="myControl" required>
<app-form-validation ngProjectAs="md-error"></app-form-validation>
</md-form-field> |
@willshowell I agree. It really seems like a bug in core. Do you mind to fill an issue there? |
Oh, these are great news! It was kind of frustrating to find out that |
I tried to reproduce to file an issue, but have had no luck. @rafaelss95, @julianobrasil could either of you look over this to make sure I'm not missing something? http://plnkr.co/edit/pF09Kc7DwZS7Wb1Mj6L8?p=preview It may actually be an issue specific to MdFormField. In that case, this issue could be repurposed to make sure |
@willshowell, I saw no problem with your code. In fact I tried something similar with We're running out of options (except for blaming |
This mess a little bit with ngProjectAs too (the icon goes to the end of the line): <md-list-item *ngFor="let note of notes">
<ng-container ngProjectAs="md-icon">
<md-icon md-list-icon>folder</md-icon>
</ng-container>
<h4 md-line>{{note.name}}</h4>
<p md-line> {{note.updated | date}} </p>
</md-list-item> |
Haven't tested by running it locally, but it looks to be due to the I suspect if it were to use Here's an updated StackBlitz of the issue. |
I think it should be fine to use |
@willshowell do you mind to send a PR? |
I gave it a shot, and I could be missing something, but it looks like I then figured you should be able to provide your custom error component as providers: [
{ provide: MatError, useClass: MyFancierError }
] but I discovered Since @rafaelss95 if you ever discover a way to achieve what you need or end up filing something in core, please report back! |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
Proposal
Currently
If a user wishes to surround
MdErrors
with a structural directive, the errors will no longer be projected inside themat-input-subscript-wrapper
.This is (sort of) expected behavior if you know that content projection works only on top level elements. Still, if you want to conditionally render your errors with
ngFor
andngIf
you have to use one of the workarounds (listed under Motivation).Proposed
Reproduction
This is an example showing how it could work
http://plnkr.co/edit/6c6Zi6m1dNAnF10smWPK?p=preview
Motivation
Couple of issues bringing this up
#5263
#5292
Workarounds:
#5263 (comment)
#5263 (comment)
The text was updated successfully, but these errors were encountered: