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>
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.
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.
<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.
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.
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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With