[Vuejs]-Generateing dynamic id attribute for radio and checkboxes in vue

0👍

Doing this solved my problem

  Vue.component('persons-phone', {
    props: {
      index: {
        type: Number,
        required: true
      },
    },
    template: `
      <div class="row person_phone_wrapper">
        <div class="col-md-4">
           <div class="form-group">
             <label for="person_phone">Phone Number: <span class="danger">*</span></label>
             <input type="tel" class="form-control required" name="person_phone[]">
           </div>
        </div>
        <div class="col-md-2">
         <div class="form-group">
           <div class="c-inputs-stacked">
             <br><br>
             <input type="checkbox" :id="checkbox" name="verified_phone[]">
             <label :for="checkbox" class="block">Verified</label>
           </div>
          </div>
        </div>

    <div class="col-md-4">
      <div>
        <br><br>
         <input :name="radio" type="radio" class="with-gap" :id="radio1" />
         <label :for="radio1">Active</label>
         <input :name="radio" type="radio" class="with-gap" :id="radio2"/>
         <label :for="radio2">Inactive</label>
     </div>
    </div>

    <div class="col-md-2">
      <div class="form-group">
        <label for="remove_person_phone"> &nbsp; </label><br>
        <button type="button" class="btn btn-danger btn-sm" @click="$emit('remove')">
          <i class="fa fa-close"></i> Remove
        </button>
      </div>
    </div>

    </div>
    `,
    data: function() {
      return {
        radio: 'phone_status['+this.index+']',
        radio1: 'radio_' + this.index,
        radio2: 'radio_' + this.index + '_' + this.index,
        checkbox: 'verified_number_'+ this.index,
      }
    }
  })

Leave a comment