I have an array selected
which holds a set of selected options. I'd like to use that array to add a disabled
attribute on those options.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Vue-js Control </title>
</head>
<body>
<div id="demo">
<select v-model="selected" multiple>
<option v-for="option in options" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
<span>Selected: {{ selected }}</span>
</div>
<script type="text/javascript" src='http://cdnjs.cloudflare.com/ajax/libs/vue/1.0.16/vue.min.js'></script>
<script type="text/javascript">
new Vue({
el: '#demo',
data: {
selected: ['A','B','D'],
options: [
{ text: 'One', value: 'A' },
{ text: 'Two', value: 'B' },
{ text: 'Three', value: 'C' },
{ text: 'Four', value: 'D' },
{ text: 'Five', value: 'E' },
{ text: 'Six', value: 'F' },
{ text: 'Seven', value: 'G' },
]
}
});
</script>
</body>
DropdownButton component can be enabled/disabled by giving disabled property. It can be disabled by setting disabled property as true .
Get Selected Value of Select Dropdown in VueCreated a select box inside the template syntax. Added an onChange() event handler. Created an options list, cars name primarily. Used the on-change method to grab the selected value using the event object.
disabled: The <select> disabled attribute is used to specify the select element is disabled. A disabled drop-down list is un-clickable and unusable. It is a boolean attribute.
Dropdown. The most common way of making a dropdown in Vue has always been this way: First, you define a toggler (usually a <button> or an <a> ) with a click event that will call a toggle method. You define the menu with a v-if directive that is bound to an active state.
You want to disable all options that are in the selected array?
<option v-for="option in options" :disabled="selected.includes(option.value)" :value="option.value">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With