0
votes

I have an array on which i am looping to get 4 switches, i have a text field that is disabled and i want to enable it when i enable one of the switch and ofcourse the field should disable when i turn off the switch. How do i achieve it?

Below is my Template and my Script that i am using.

 <div class="body-2">Hello There:</div>
      <div class="caption">This is Some Text</div>
      <v-switch :v-model="`${project.model}`" v-for="project in projects" 
      :key="project.status" 
      :label="`${project.status}`"></v-switch>
      <v-text-field :disabled="!enabled" label="This is My Label"</v-text-field>




export default{
    data(){
    return{
    enabled:false,
    projects:
    [ {status:"Text1", model:"enabled1"},
    {status:"Text2",model:"enabled2"},
    {status:"Text3",model:"enabled3"},
    {status:"Text4",model:"enabled4"}
       ]
2

2 Answers

0
votes

I'm not familiar with vuetify, but if you could simply use the .model property of each project object as the switch v-model, you could make .enabled a computed property instead of a data property:

computed: {
    enabled() {
        return this.projects.some(project => project.model);
    }
}
0
votes

I believe you are trying to enable the input if one switch is on but have it disabled if all four switches are off.

The disabled property can be bound to a computed property that returns false if one of the switches is on and true if all four switches are off.

If this is a custom component, another options is to emit a custom event from the child component (v-switch) that emits whether the switch is on or off, and then call a method that sets a Boolean that you bind to :disabled.