Contents
- Setting input length
- Disable inputs
- CssClass
Having trouble getting help?
Contact Support
Contact Support
Appearance in EJ2 JavaScript OTP Input control
18 Jul 20248 minutes to read
You can also customize the appearance of OTP Input control.
Setting input length
You can specify the length of OTP by using the length property. The default value is 4
.
// Initializes the OTP Input control
var otpInput = new ej.inputs.OtpInput({
length: 5
});
// Render initialized OTP Input.
otpInput.appendTo('#otp_default');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 - OTP Input</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="description" content="Essential JS 2">
<meta name="author" content="Syncfusion">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<!--style reference from app-->
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='container' style="width: 400px;">
<div id="otp_default"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>
#container {
visibility: hidden;
margin: 50px auto;
width: 350px;
}
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
Disable inputs
You can disable the OTP Input control by using the disabled property. By default the value is false
.
// Initializes the OTP Input control
var otpInput = new ej.inputs.OtpInput({
value: 1234,
disabled: true
});
// Render initialized OTP Input.
otpInput.appendTo('#otp_disabled');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 - OTP Input</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="description" content="Essential JS 2">
<meta name="author" content="Syncfusion">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<!--style reference from app-->
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='container' style="width: 350px;">
<div id="otp_disabled"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>
#container {
visibility: hidden;
margin: 50px auto;
width: 350px;
}
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
CssClass
You can customize the appearance of the OTP Input control, such as by changing its colors, fonts, sizes or other visual aspects by using the cssClass property.
The OTP input control supports the following predefined styles that can be defined using the cssClass
property. You can customize by replacing the cssClass
property with the below defined class names.
cssClass | Description |
---|---|
e-success |
Used to represent a positive action. |
e-warning |
Used to represent an action with caution. |
e-error |
Used to represent a negative action. |
// Initializes the OTP Input control
var otpInput = new ej.inputs.OtpInput({
value: 1234,
cssClass: 'e-success'
});
// Render initialized OTP Input.
otpInput.appendTo('#custom_otp');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 - OTP Input</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="description" content="Essential JS 2">
<meta name="author" content="Syncfusion">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<!--style reference from app-->
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='container' style="width: 350px;">
<div id="custom_otp"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>
#container {
visibility: hidden;
margin: 50px auto;
width: 350px;
}
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}