Placeholder in EJ2 TypeScript OTP Input control
18 Jul 20245 minutes to read
The placeholder in OTP Input specifies the text that is shown as a hint or placeholder until the user enters a value in the input field. It acts as a guidance for the users regarding the expected input format or purpose of the input field.
You can set the placeholder text by using the placeholder property. Additionally, when providing a single character as the placeholder value all input fields within the OTP Input control will display the same character.
import { OtpInput } from "@syncfusion/ej2-inputs";
// Initializes the OTP Input control
let otpInput: OtpInput = new OtpInput({
placeholder: "x"
});
// Render initialized OTP Input.
otpInput.appendTo('#default_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/31.1.17/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-inputs/styles/material.css" rel="stylesheet" />
<!--style reference from app-->
<link href="index.css" rel="stylesheet" />
<!--system js reference and configuration-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>LOADING....</div>
<div id='container' style="width: 350px;">
<div id="default_otp"></div>
</div>
</body>
</html>
#container {
visibility: hidden;
margin: 50px auto;
width: 350px;
}
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
When a placeholder with multiple placeholder characters is provided each input field will display characters from the placeholder string in sequence based on the available OTP input length.
import { OtpInput } from "@syncfusion/ej2-inputs";
// Initializes the OTP Input control
let otpInput: OtpInput = new OtpInput({
placeholder: "wxyz"
});
// Render initialized OTP Input.
otpInput.appendTo('#default_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/31.1.17/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/31.1.17/ej2-inputs/styles/material.css" rel="stylesheet" />
<!--style reference from app-->
<link href="index.css" rel="stylesheet" />
<!--system js reference and configuration-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>LOADING....</div>
<div id='container' style="width: 350px;">
<div id="default_otp"></div>
</div>
</body>
<style>
#container {
visibility: hidden;
}
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
</html>
#container {
visibility: hidden;
margin: 50px auto;
width: 350px;
}
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}