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

<md-input> should work with [attr.required] #1217

Closed
rolandjitsu opened this issue Sep 9, 2016 · 3 comments
Closed

<md-input> should work with [attr.required] #1217

rolandjitsu opened this issue Sep 9, 2016 · 3 comments
Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround

Comments

@rolandjitsu
Copy link

rolandjitsu commented Sep 9, 2016

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Consider the following scenario:

<md-input [formControlName]="field.key" [type]="field.type" [id]="field.key" [placeholder]="field.label" [value]="field.value" [required]="field.required">

I would expect that when field.required is false, <md-input> should take notice of that, which it does. The problem occurs with formControlName, because the attribute required will be on the input (as required="false") even if it is set to false, which means that the control because required due to the presence of the attribute.

I can use attr.required:

<md-input [formControlName]="field.key" [type]="field.type" [id]="field.key" [placeholder]="field.label" [value]="field.value" [attr.required]="field.required">

But the above introduces a different problem with <md-input>, as in it no longer marks the component as required (missing *).

What is the current behavior?

<md-input> should work with attr.required as well, as the HTML spec does not required the attribute to have a value or not, having it on the input element is enough to mark it as required.

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: http://plnkr.co/edit/o077B6uEiiIgkC0S06dd

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

Properly marking <md-input> as required is necessary in order to follow the specs and to provide a visual indication to the user that the field must be filled.

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

Angular 2 RC.5
Angular 2 Material 2.0.0-alpha.7-4

Is there anything else we should know?

@angular/forms works with [attr.required], there are no obvious bugs coming from there.
The problem might be at input.html#L27, instead of [required]="required" it should be [attr.required]="required || null" (null must be set in order for the attribute not be rendered).

@rolandjitsu rolandjitsu changed the title <md-input> should work with attr.required <md-input> should work with [attr.required] Sep 9, 2016
@jelbourn jelbourn added the P2 The issue is important to a large percentage of users, with a workaround label Sep 29, 2016
@harsha00790
Copy link

I am having the same issue. Could you get any workaround/fix to beat this bug.

@jelbourn
Copy link
Member

jelbourn commented May 4, 2017

This is obsolete now that we have md-input-container.

@jelbourn jelbourn closed this as completed May 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 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

No branches or pull requests

4 participants