Validation in Angular TextBox component
26 Oct 20242 minutes to read
The TextBox supports three types of validation styles namely error
, warning
, and success
. These states are enabled by adding corresponding classes .e-error
, .e-warning
, or .e-success
to the cssClass property.
import { FormsModule } from '@angular/forms'
import { TextBoxModule } from '@syncfusion/ej2-angular-inputs';
import { Component } from '@angular/core';
@Component({
imports: [
TextBoxModule,
FormsModule
],
standalone: true,
selector: 'app-root',
template: `<div class="wrap">
<ejs-textbox placeholder = "Input with warning" cssClass="e-warning"></ejs-textbox>
<ejs-textbox placeholder = "Input with error" cssClass="e-error"></ejs-textbox>
<ejs-textbox placeholder = "Input with success" cssClass="e-success"></ejs-textbox>
</div>`
})
export class AppComponent {
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Adding mandatory asterisk to placeholder and float label
You can add a mandatory asterisk(*)
to placeholder and float label using .e-float-input.e-control-wrapper .e-float-text::after class.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import {TextBoxModule} from '@syncfusion/ej2-angular-inputs'
import { Component } from '@angular/core';
@Component({
imports: [
TextBoxModule
],
standalone: true,
selector: 'app-root',
template: `<div class="wrap">
<h4>Floating label as auto</h4>
<div class='textboxes'>
<ejs-textbox placeholder="First Name" floatLabelType="Auto"></ejs-textbox>
</div>
<h4>Floating label as always</h4>
<div class='textboxes'>
<ejs-textbox placeholder="First Name" floatLabelType="Always"></ejs-textbox>
</div>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));