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

Add md-no-asterisk to inputs #3681

Closed
prowwid opened this issue Mar 20, 2017 · 14 comments · Fixed by #4237
Closed

Add md-no-asterisk to inputs #3681

prowwid opened this issue Mar 20, 2017 · 14 comments · Fixed by #4237
Assignees
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix help wanted The team would appreciate a PR from the community to address this issue

Comments

@prowwid
Copy link

prowwid commented Mar 20, 2017

Bug, feature request, or proposal:

request

What is the current behavior?

There is no ability to remove asterisks from placeholders in inputs with required attribute.

What is the expected behavior?

We need an ability to disable asterisks on required inputs like in the first version of material UI by using "md-no-asterisk" attribute in input.

In the end, it would be good enough to have syntax like in the following example:
Plunker md-no-asterisk example

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

For now, there are two hacks to remove asterisks from inputs:

  1. do not use "required" attribute
  2. use "required" attribute with hacks that would hide or remove automatically added asterisk

Both options are crutches. And as you know crutches are really bad things.

@mizdler
Copy link

mizdler commented Mar 21, 2017

I think currently simplest solution is to change mat-placeholder-required CSS class:
.mat-placeholder-required { display: none; }

@jelbourn jelbourn added feature This issue represents a new feature or feature request rather than a bug or bug fix discussion labels Mar 21, 2017
@prowwid
Copy link
Author

prowwid commented Mar 22, 2017

Hi, @mizdler

Yes, you are right.
But, as I've already said in the description, it is a hack.

If we do not need asterisk It would be really nice to have the ability to disable asterisk in input without modification of styles.
For example, login credentials - both nickname and password are required but who would mark those fields was asterisks?

@jefersonestevo
Copy link
Contributor

I agree that this option should be available, but I think it may be used as a mdInput @Input() property, like the disableRipple property from md-list.

Something like:
<input type="text" mdInput required ... mdNoAsterisk />

Or it'll be better just to be named noAsterisk ?

If you want I can send a PR with this change.

@ryanp-bitfocus
Copy link

In material 1 mdNoAsterisk already existed and worked for this purpose. As seen on the documentation here https://material.angularjs.org/latest/api/directive/mdInput

@mbeckenbach
Copy link

@prowwid
Why should one not want to customize CSS in components styles and make usw of view encapsulation?

@M-a-c
Copy link
Contributor

M-a-c commented Apr 6, 2017

@mbeckenbach I think the idea is you specified something and it changed what you expected, maybe they shouldn't have been rendered in the first place.

https://material.io/guidelines/components/text-fields.html#text-fields-layout the spec says that "In forms with some required fields, indicate all of the required ones. However, if there are fewer optional fields, indicate those instead"

So essentially to get the proper functionality where a form has more optional fields than required fields you have to do something hacky with the styles instead of telling the component to not use the asterisks.

It seems to meet the spec, users should be able to turn off the asterisks.

@jefersonestevo go for the pr see what happens? ¯\(ツ)

@mmalerba
Copy link
Contributor

Talked with @jelbourn, we're up for adding a hideRequiredMarker attribute to md-input-container. Anyone want to take this on?

@mmalerba mmalerba added help wanted The team would appreciate a PR from the community to address this issue and removed discussion labels Apr 10, 2017
@M-a-c
Copy link
Contributor

M-a-c commented Apr 10, 2017

@mmalerba I might be able to, but @jefersonestevo said they could submit a pr.
Is there a component you can point to that has a similar disable option?

@mmalerba
Copy link
Contributor

The required field on MdInputDirective is a good example for how to do a boolean @Input() https://github.com/angular/material2/blob/master/src/lib/input/input-container.ts#L162

@M-a-c
Copy link
Contributor

M-a-c commented Apr 10, 2017

Awesome thanks!

@prowwid
Copy link
Author

prowwid commented Apr 14, 2017

Hi @mbeckenbach

Why should one not want to customize CSS in components styles and make usw of view encapsulation?
because

Because customization of CSS is a hack for this use-case. If you don't need an asterisk - don't even render it.

Basically input component does more work than it should and renders redundant content.
In our systems, we have a lot of inputs and most of them are required but design dictates not to use asterisks. So we receive a lot of redundant HTML using "required" in inputs.

jefersonestevo added a commit to jefersonestevo/material2 that referenced this issue Apr 24, 2017
…ntainer

This attribute will enable the user to hide the required marker (star) fron an mdInput even when it's required

Fixes angular#3681
@jefersonestevo
Copy link
Contributor

@mmalerba I've created the PR #4237 to add the attribute hideRequiredMarker to the md-input-container. Please give it a look when you have some time.

Thanks

mmalerba pushed a commit that referenced this issue Apr 25, 2017
* fix(input-container): New attribute hideRequiredMarker to md-input-container

This attribute will enable the user to hide the required marker (star) fron an mdInput even when it's required

Fixes #3681

* fix(input-container): Checking if the input container placeholder has the '*' before applying the 'hideRequiredMarker' attribute on test. Removing extra leading space on hideRequiredMarker demo.
@roelzkie15
Copy link

roelzkie15 commented Aug 1, 2017

Is this isn't available on md-select component? i have material2 v2.0.0-beta.8

Because i got this error:

Template parse errors: Can't bind to 'hideRequiredMarker' since it isn't a known property of 'md-select'.

@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 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix help wanted The team would appreciate a PR from the community to address this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants