Bahaeddine SAHLI
Bahaeddine SAHLI

Reputation: 1

Dynamic V-model name in a v-for loop Vue

I am developing an application and I am using Vue and laravel , inside a v-for loop I need error.id in the loop to be bound to the v-model name of the elements, this my code:

 <tbody class="bodycol">
 <tr v-for="error in errors.error" :key="error.id" >

  <td>{{ error.client }}</td>
  <td>{{ error.session }}</td>
  <td>{{ error.info_session }}</td>
  <td>{{ error.UPROC }}</td>
  <td>{{ error.num_session }}</td>
  <td>{{ error.num_exec }}</td>
  <td>{{ error.date_debut }}</td>
  <td>{{ error.heure_debut }}</td>
  <td>{{ error.date_fin }}</td>
  <td>{{ error.heure_fin }}</td>
    <td>{{ error.status }}
    <form @submit="addComment(error.id)" >
    <div class="form-group">
      <input v-model="form.comment[error.id]" type="text" name="comment"
                  class="form-control area" :class="{ 'is-invalid': form.errors.has('comment') }" 
      required>
                  <has-error :form="form" field="comment"></has-error>
      </div>
        </form>
    </td>
</tr>

   data(){
  return{
   comment:[],
    }
     }

the problem is the output of the errors.status is:

[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"the comment is here"]

Upvotes: 0

Views: 97

Answers (1)

Potato Science
Potato Science

Reputation: 602

Change your data to this. You are referencing form.comment not comment

export default {
    data() {
        return {
            form: {
                comment: []
            }
        }
    }
}

Upvotes: 2

Related Questions