I am using vueJs and have a radio button group. When the radio is checked how can I bind a css border attribute to a class :class="selected"?
The :checked attribute does not work as I have bound it to the v-model.
So if the radio is checked bind a class (selected) to the div.
<div class="sau-select lg center" :class="selected">
   <label for="windows">
      <input type="radio" id="windows" value="windows" v-model="selectedOs" :checked="checked">
      <span></span>
      <img src="/img/windows.gif" alt="Windows">Windows
   </label>
</div>
                You can perform a condition against the checked property value of the radio button. Each of the radio buttons needs to be set a unique value. Let's say we have two radio buttons that will have a label text 'Yes' and 'No' with a supplied value of 1 represents the Yes value and 2 represents the No value.
isCheckAll — It is a boolean type variable. This use to find whether checkall checkbox checked or not. languages — An Array type variable. It is used on the v-model directive of checkboxes.
It provides two-way data binding by binding the input text element and the value binded to a variable assigned.
lazy. By default, v-model syncs with the state of the Vue instance (data properties) on every input event - which means every single time the value of our input changes. The . lazy modifier changes our v-model so it only syncs after change events. The change event is triggered when a change is commited.
The :class="selected" you use hasn't much effect.
To conditionally apply a class to the div, you will have to use as :class condition if the selectedOs equals the value attribute of each <input>, such as :class="{redborder: selectedOs === 'windows'}". More details in the demo below:
new Vue({
  el: '#app',
  data: {
    selectedOs: 'windows'
  }
})
.redborder { border: 1px solid red; }
<script src="https://unpkg.com/vue"></script>
<div id="app">
  <label :class="{redborder: selectedOs === 'windows'}">
    <input type="radio" value="windows" v-model="selectedOs"> Windows
  </label>
  <label :class="{redborder: selectedOs === 'linux'}">
    <input type="radio" value="linux" v-model="selectedOs"> Linux
  </label>
</div>
Notice that value="linux" means that that radio box will assign the string "linux" to the v-model variable (in this case selectedOs). value="linux" is equivalent to :value="'linux'", for instance.
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