-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
MdInput doesn't set required asterisk when the validator is set in reactive forms #2574
Comments
Likely the same problem as the one that this PR fixes #2565 |
Probably not exactly the same because the control does not have a |
Yeah but the underlying problem seems to be the same, only checking the existence of the |
This comment has been minimized.
This comment has been minimized.
While you are at it... the |
Currently there isn't a great way to determine if Validators.required has been added to the control because form validators are combined into an aggregate function at setup. I think the correct solution to this might be to add a better way to retrieve individual validators in core In the meantime, you'll have to use the required property binding when using md-select or md-input with reactive forms. You'll probably want to use it with the Validators.required to avoid changed after checked errors. I'll keep this open so we can track, but I think the change will have to be in core first. |
@kara thanks for the info. I guess we'll have to wait then :-) ..and Kara is right, there seems not to be a great way to get a hold of the
|
Using the required attribute doesn't work well if the input is inside an ngIf I have found. The core forms automatically adds the required validator to the control when the required attribute is used on the input but it doesn't go away once the input is no longer in the dom. Maybe that's a separate issue for the core side not cleaning up when an element is removed from the dom. This leads to a form appearing invalid when it shouldn't be. |
I'm using this solution:
|
Knowing if the required validation was added or not doesn't seems like something that core angular is going to support, because validators are just functions. |
Related to angular/angular#13461 |
@ajaysattikar That would be template-driven forms. This whole discussion is about reactive forms. |
@isherwood Yes, sorry. Edited to avoid confusion. |
@eltonplima except that it disappears as soon as the form is valid, which means that it would cause problems with for example the outline appearance, along with missing edit: nevermind, you can use status changes with filter to get validity change edit2: ok, that's not gonna work, what I would need is an observable array of errors / validity states......... which of course you can't get.... angular/angular#10530 ffs... |
This comment has been minimized.
This comment has been minimized.
Yes |
I think my issue is a bit different... Material/ReactiveForm is completely ignoring the required validation when I'm using the CVA so also I'm passing errorStateMatcher but still not work... The input is not getting red borders and neither the asterisk, it's like is a not required input.. any suggestion to deal with that? |
@BruneXX have you checked so that your control is correct? does {{ yourControl.errors }} contain an object? |
Hi @mackelito yep, it already has an object and it's correct, but I've already solved that, subscribing it to statusChanges of the parent form, the sad thing is that I've to pass the parent fromGroup in order to subscribe, unfortunately I haven't found other way to make it work. |
This is exactly what I hope to avoid 😬 |
@mackelito haha me too, but sadly I don't have too much time to review that.. I had to go with that approach until found another way. |
@BruneXX I have been trying on and off for like 2 days now.. not sure I can put more time on it 😄 |
@BruneXX Wohoo.. I just solved my issue.. almost to simple.. I just needed to add the [formControl]...
So only thing missing was to attach the formcontrol to the input.. Badabom badabing! :D |
@mackelito Excellent! 👍 I've tried something like that some days ago, but I've ran into the circular dependency like you said in your code comment and I've leaved as it was, maybe I'll give this a second try later. Thank you! |
@BruneXX sounds like you are using the provider for NG_VALUE_ACCESSOR?.. if so.. remove it :) |
FYI.. it works but another error in the console...
Not sure yet what it referes to :) |
Hi, this is my long used solution, It handles validator changes too. 2 directives handling change
2 monkey patches for adding extra logic to validation
Custom required validator that uses
|
This solution worked perfectly along with formControlName. Thanks! |
Now that angular/angular#42838 has landed we should be able to implement this |
…ator Resolves the long-standing issue where the required asterisk wasn't being shown in the form field label when using the `required` validator from Forms. Fixes angular#2574.
…ator Resolves the long-standing issue where the required asterisk wasn't being shown in the form field label when using the `required` validator from Forms. Fixes angular#2574.
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:
The
placeholder
from the MdInput does not show the asterisk (*) when we useValidators.required
in theFormControl
.What is the expected behavior?
The asterisk should be shown as it is when setting the
required
attribute.What are the steps to reproduce?
http://plnkr.co/edit/XqkOmF502Q8RFj8qcUwp?p=preview
or take a look at the input-container-demo
What is the use-case or motivation for changing an existing behavior?
To be not dependet on the template to visually indicate that the input is required.
Which versions of Angular, Material, OS, browsers are affected?
all (to my knowlege it never worked)
The text was updated successfully, but these errors were encountered: