Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove asterisk in required field and replace a custom asterisk in before place holder in angular 2+ and angular material2

I am using angular5 and angular material2. I want to remove asterisk or star sign for the required field. I also want to add a custom asterisk or star sign before the place holder.

<mat-form-field>
      <input matInput placeholder="Applicant Name" name="inputApplicantName" 
      [(ngModel)]="inputApplicantName" required>
 </mat-form-field>
like image 479
monir tuhin Avatar asked Apr 08 '18 06:04

monir tuhin


People also ask

How do I hide asterisk required?

There is actually a built-in option to change/remove the required field indicator. In the form builder, you can click on your field, open up the “Advanced” panel, and here you will see a box for “Required field indicator” that has an asterisk in it by default. Simply delete the asterisk and save your form.

Are asterisk required?

Asterisk (*) next to a form control's label usually indicates it as "required". Oftentimes, this asterisk's purpose is then explained somewhere else on the page. Many users (especially screen reader users) may be confused with that, so be sure to make this information is easily accessible.

What is mat form field infix?

<mat-form-field> is a component used to wrap several Angular Material components and apply common Text field styles such as the underline, floating label, and hint messages.

What is Mat label?

mat-label is similar to labels which we use in normal HTML forms. But the advantage with mat-label is that it has pre-defined CSS style classes and animations defined in it.


2 Answers

To remove the asterisk, you can use hideRequiredMarker attribute.

<mat-form-field hideRequiredMarker>
    <input matInput placeholder="Applicant Name" name="inputApplicantName" 
      [(ngModel)]="inputApplicantName" required>
</mat-form-field>
like image 110
Pedro Romero Avatar answered Nov 15 '22 21:11

Pedro Romero


remove "required" attribute from input; replace placeholder attribute with tag inside of mat-form-field, and try to play with styles of it;

A placeholder is a text label displayed in the input area when the input does not contain text. When text is present, the placeholder will float above the input area. The placeholder can be specified either via a placeholder attribute on the input or a < mat-placeholder > element in the same form field as the matInput

like image 40
Alexandr2134 Avatar answered Nov 15 '22 23:11

Alexandr2134