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

MdInputDirective uses required attribute only to add the placeholder asterisk #4090

Closed
calbot opened this issue Apr 13, 2017 · 2 comments
Closed

Comments

@calbot
Copy link

calbot commented Apr 13, 2017

Bug, feature request, or proposal:

Bug/Proposal

What is the expected behavior?

Basically the problem is I can't use the required attribute with mdInput in my "reactive" code based form. This is because it automatically adds validators to the form control which causes problems when a field is added or removed through ngIf. These fields which are marked required will keep the required validator on the form control even after the field is no longer in the dom.

What is the current behavior?

required field is incompatible with reactive forms.

What are the steps to reproduce?

Providing a Plunker (or similar) is the best way to get the team to see your issue.
Plunker template: https://goo.gl/DlHd6U

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

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

Is there anything else we should know?

lib/input/input-container.html

Uses the "required" attribute only

<span class="mat-placeholder-required" *ngIf="_mdInputChild.required">*</span>
Maybe if there was another attribute it would be helpful for reactive forms users who don't want the automatic validators added by Angular framework...

<span class="mat-placeholder-required" *ngIf="_mdInputChild.required || _mdInputChild.mdRequired">*</span>

Basically I end up working around this by doing the following ...

  @ViewChildren(MdInputDirective)
  private inputDirectives: QueryList<MdInputDirective>;

Then I set the mdinput.required = true manually to trick material to show the asterisk so I don't have the issues with the automatically added validators.

@jelbourn
Copy link
Member

Dupe of #2574

@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 5, 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

2 participants