Having trouble getting help?
Contact Support
Contact Support
Add floating label to read only textbox in EJ2 TypeScript Textbox control
15 May 20233 minutes to read
You can achieve floating label for read-only textboxes by adding/removing e-label-top
and e-label-bottom
classes to the label element
In this sample, click the update value button to fill the read-only textbox with value and float a label.
import { InputObject, TextBox } from '@syncfusion/ej2-inputs';
let readonlyTextBox: TextBox = new TextBox({
placeholder: 'Readonly Textbox',
readonly: true,
floatLabelType: 'Auto',
});
readonlyTextBox.appendTo('#readonly');
document.getElementById('setValueButton').addEventListener('click', function () {
readonlyTextBox.value = '10';
});
document.getElementById('clearValueButton').addEventListener('click', function () {
readonlyTextBox.value = ''; // Clear the value
});
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 TextBox</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 TextBox Components" />
<meta name="author" content="Syncfusion" />
<link href="//cdn.syncfusion.com/ej2/21.2.3/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/21.2.3/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/21.2.3/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="index.css" rel="stylesheet" />
<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' class="text_value">
<div id="input-container"></div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-lg-6 col-md-6">
<div>
<input id="readonly" type="text" />
</div>
</div>
</div>
<div class="row">
<div class="col-xs-10 col-sm-10 col-lg-10 col-md-10">
<button class="e-btn" id="setValueButton">Set Value</button>
<button class="e-btn" id="clearValueButton">Clear Value</button>
</div>
</div>
</div>
</body>
</html>