Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove asterisk from required field in Angular Material

When defining a input field as required in angular material, it automatically adds a asterisk after the label. I've found a lot of questions asking how to add it, but none how to remove it. It seems that it wasn't default at the time they asked it, but according to this reference now it is the default behaviour (I'm using the version available on https://github.com/angular/material **). How do I remove it and get the same behavior as shown here by @Styx.

**By the time I had this problem I thought that I was using the latest release (v. 1.0.5), but I was in fact using the master version, which could have the asterisk feature.

like image 786
Hugo Oshiro Avatar asked Feb 17 '16 17:02

Hugo Oshiro


People also ask

How do I hide an asterisk?

Removing the Required AsteriskGo to Style > Text > Text Options and uncheck the option Show Required Asterisks.

What is Mandatory fields are marked with an asterisk *?

Fields marked with * are mandatory Using an asterisk (*) symbol content authors notify mandatory field. This is said to be one of the accessible modes of identifying a mandatory field, however this method also will be a problem with screen readers in certain times.


2 Answers

Even though it looks like this feature is not yet in 1.0.5, release notes ...

I looked through this commit, and this probably is what we are looking for:

md-no-asterisk

<input md-maxlength="30" required md-no-asterisk name="description" ng-model="project.description">

This is the closed issue for this feature, status says 'needs: merge'

like image 138
oKonyk Avatar answered Nov 15 '22 06:11

oKonyk


When using Angular Materials mat-form-field you can add the hideRequiredMarker

<mat-form-field hideRequiredMarker>
  <input required placeholder="type here">
</mat-form-field>

Credits to @shivek-parmar How do I remove asterisk from required field in Angular Material and add (optional) beside label for optional labels

like image 26
Severin Klug Avatar answered Nov 15 '22 07:11

Severin Klug