Set the disabled state in Vue Textbox component
11 Jun 20247 minutes to read
Disable the TextBox by adding the e-disabled
to the input parent element and set disabled
attribute to the input element.
<template>
<div class='wrap'>
<div id='input-container'>
<input class="e-input" type="text" placeholder="Enter Name" disabled />
<div class="e-float-input e-disabled">
<input type='text' required disabled />
<span class="e-float-line"></span>
<label class="e-float-text">Enter Name</label>
</div>
</div>
</div>
</template>
<script setup>
import { onMounted } from 'vue';
onMounted(() => {
// To get the all input fields and its container.
let inputElement = document.querySelectorAll('.e-input-group .e-input,.e-float-input.e-input-group input');
// Add 'e-input-focus' class to the input for achive ripple effect when focus on the input field.
for (let i = 0; i < inputElement.length; i++) {
inputElement[i].addEventListener('focus', () => {
let parentElement = inputElement[i].parentNode;
if (parentElement.classList.contains('e-input-in-wrap')) {
parentElement.parentNode.classList.add('e-input-focus');
} else {
inputElement[i].parentNode.classList.add('e-input-focus');
}
});
inputElement[i].addEventListener('blur', () => {
let parentElement = inputElement[i].parentNode;
if (parentElement.classList.contains('e-input-in-wrap')) {
parentElement.parentNode.classList.remove('e-input-focus');
} else {
inputElement[i].parentNode.classList.remove('e-input-focus');
}
});
}
});
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-inputs/styles/material.css";
.wrap {
box-sizing: border-box;
margin: 0 auto;
padding: 20px 10px;
width: 340px;
}
</style>
<template>
<div class ='wrap'>
<div id ='input-container'>
<input class="e-input" type="text" placeholder="Enter Name" disabled/>
<div class="e-float-input e-disabled">
<input type='text' required disabled/>
<span class="e-float-line"></span>
<label class="e-float-text">Enter Name</label>
</div>
</div>
</div>
</template>
<script>
export default {
data: function() {
return { }
},
mounted: function() {
// To get the all input fields and its container.
let inputElement = document.querySelectorAll('.e-input-group .e-input,.e-float-input.e-input-group input');
// Add 'e-input-focus' class to the input for achive ripple effect when focus on the input field.
for (let i = 0; i < inputElement.length; i++) {
inputElement[i].addEventListener('focus', () => {
let parentElement = this.parentNode;
if (parentElement.classList.contains('e-input-in-wrap')) {
parentElement.parentNode.classList.add('e-input-focus');
} else {
this.parentNode.classList.add('e-input-focus');
}
});
inputElement[i].addEventListener('blur', () => {
let parentElement = this.parentNode;
if (parentElement.classList.contains('e-input-in-wrap')) {
parentElement.parentNode.classList.remove('e-input-focus');
} else {
this.parentNode.classList.remove('e-input-focus');
}
});
}
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-inputs/styles/material.css";
.wrap {
box-sizing: border-box;
margin: 0 auto;
padding: 20px 10px;
width: 340px;
}
</style>