How to Conditionally Disable the Input in VueJS ? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In VueJS, we can conditionally disable the input-taking field. In this article, we will learn to conditionally disable the input-taking field by using two different approaches listed below: Table of Content Using :disabled PropertyUsing v-if and v-elseUsing :disabled PropertyIn this approach, we are using the :disabled property to conditionally disable the input field which is based on the boolean variable disableCheck. When the button is clicked, the event occurs and the input field is been disabled. Syntax:<input type="text" v-model="inputVal" :disabled="disableCheck">Example: The below code example illustrates the use of the :disabled property to conditionally disable the input taking in VueJS. HTML <!DOCTYPE html> <html> <head> <title>Example 1</title> </head> <body> <div id="app"> <input type="text" v-model="inputVal" :disabled="disableCheck"> <button @click="changeDisable"> {{ disableCheck ? 'Enable Input' : 'Disable Input' }} </button> </div> <script src= "https://cdn.jsdelivr.net/npm/vue@2"> </script> <script> new Vue({ el: '#app', data: { inputVal: '', disableCheck: false }, methods: { changeDisable() { this.disableCheck = !this.disableCheck; } } }); </script> </body> </html> Output: Using v-if and v-elseIn this approach, we are using the v-if and v-else directives to conditionally render input fields based on the value of the condition variable. When a user clicks on the button the input field is been switched and a disabled input field is been shown. Syntax:<input v-if="!condition" v-model="textInput"><input v-else :readonly="true" :style="{ 'background-color': '#eee' }" v-model="textInput">Example: The below code example illustrates the use of a v-if and v-else to conditionally disable the input taking in VueJS. HTML <!DOCTYPE html> <head> <title>Example 2</title> <script src="https://cdn.jsdelivr.net/npm/vue@2"></script> </head> <body> <div id="app"> <h1> Using v-if and v-else</h1> <button @click="disableCondition"> Toggle Input </button> <input v-if="!condition" v-model="textInput"> <input v-else :readonly="true" :style="{ 'background-color': '#eee' }" v-model="textInput"> </div> <script> new Vue({ el: '#app', data: { textInput: '', condition: true }, methods: { disableCondition: function () { this.condition = !this.condition; if (this.condition) { this.textInput = ''; } } } }); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to Conditionally Disable the Input in VueJS ? G gpancomputer Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League Vue.JS Geeks Premier League 2023 +1 More Similar Reads How to Conditionally Disable a Form Input in React-Bootstrap ? In this article, we will see how to conditionally disable a form input in React-Bootstrap. React-Bootstrap is a popular open-source library for building frontend components with the advantage of the pre-build component features of Bootstrap. Creating React Application And Installing ModuleStep 1: Cr 3 min read How to Disable a Button Conditionally in JavaScript? In JavaScript, you can conditionally disable buttons based on specific criteria to control user interactions. Using simple if-else statements or event listeners, you can dynamically enable or disable buttons depending on form validation, user actions, or other conditions. This helps regulate the ava 3 min read How to Disable Ctrl+V (Paste) in JavaScript? What is Ctrl + V ?The ctrl+V is a keyboard shortcut used to paste anything from anywhere. It can be disabled for a particular task or page. Let's see how to disable cut, copy, paste, and right-click. To disable the ctrl+V (paste) keyboard shortcut in JavaScript, you would typically capture the keydo 3 min read How to disable input type text area? To disable an input type=text by using the input disabled attribute. A disabled input is un-clickable and unusable. It is a Boolean attribute. The disabled elements are not submitted in the form. Syntax: <input type="text" disabled>Example 1: To disable an input field of type "text" by using t 2 min read How to Disable Input in JavaScript ? Disabling input fields in JavaScript is a common task when you want to restrict users from interacting with specific form elements. This can be useful in various scenarios, such as preventing modifications to fields that are conditionally locked or ensuring certain inputs are controlled programmatic 2 min read How to change the font-color of disabled input using CSS ? In this article, we are going to learn how to change the font-color of disabled input. There is a method to solve this problem, which is discussed below: Approach: With adding basic CSS property we are able to change the font-color of a disabled input. The disabled input element is unusable and un-c 2 min read How to Conditionally Add an Attribute for an Element in VueJS? In VueJS, it's common to add attributes dynamically to HTML elements based on certain conditions. This allows for greater flexibility and control when rendering elements. Vue.js provides several ways to conditionally add or remove attributes depending on data, logic, or component state. we will expl 2 min read How to Disable a Button in React JS ? Disabling a button in React JS means making it unclickable and visually indicating its unavailability. This is done by setting the button's disabled attribute to true. It's used for controlled interactions, like form submissions with valid data.A disabled button becomes unclickable and visually sign 4 min read How to create a Disabled Input using jQuery Mobile ? jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating a Disabled Input using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. <link rel=âstylesheetâ hre 1 min read How to disable radio button using JavaScript ? Radio buttons let users select one option from many, commonly used in forms. Sometimes, based on a user's previous choice, certain options need to be disabled. For example, if a user selects "No" to playing games, we can disable related game options. Using JavaScript, about 65% of forms use such log 4 min read Like