0

i have table in vue component and one of the column have input also tr tag in v-for. how can i get all table value and submit in one time? i mean fill all inputs and save method run one time for all of them

<table >
    <thead>
    <tr>
        <th>NO</th>
        <th>Costumer Name</th>
        <th>Total Amount</th>
        <th>Total Paid</th>
        <th>Total Refund</th>
        <th>Actual Paid</th>
        <th>Balance</th>
        <th>New Pay</th>
    </tr>
    </thead>
    <tbody>

    <tr v-for="(passenger , index) in passengers">
        <td >{{ index+1 }}</td>
        <td >{{ passenger.name_ar }}</td>
        <td >{{ passenger.payment }}</td>
        <td >{{ passenger.payments+' KD' }}</td>
        <td >{{ passenger.returned+' KD' }}</td>
        <td >{{ passenger.payment.paid }}</td>
        <td >{{ passenger.payment.total_amount }}</td>
        <td >
            <div class="form-group">
                <div class="input-group">
                    <input type="text" class="form-control" :ref="passenger.id">
                </div>
            </div>
        </td>


    </tr>
    </tbody>

</table>

3
  • What specifically are you stuck on, can you show us how far you got? You already have all the passenger data. So just add a v-model to the input and you have everything. vuejs.org/v2/guide/forms.html Commented Jun 23, 2020 at 12:13
  • @Trevor i have several inputs (all tr tags have input) and all of my inputs have one v-model whit same name and that is wrong Commented Jun 23, 2020 at 12:16
  • v-model allows you to set an object key. v-model="passenger.input[index]" like that Commented Jun 23, 2020 at 12:20

2 Answers 2

1

You could achieve this with v-model as suggested by others.

//****** Add v-model to your input**********
<input type="text" class="form-control" v-model="thispassenger" :ref="passenger.id">

In your Template have a button that will handle the submit method:

<button type="submit" @click="addPassaenger">Add Passenger</butoon>

Now you have to define thispassenger data object

export default {
  data() {
     return {  thispassenger : {} }
  },
// ****** method to handle the submit
methods: {
    addPassaenger() {
       //put your submit logic here
       // example axios.post('url', this.thispaasenger);
    }
 }
}

Remember that v-model directive creates two-way data bindings on form input, textarea, and select elements. You can't use use it on any other elements.

If you want to learn more about v-model, please o to this link.Form Input Bindings

Sign up to request clarification or add additional context in comments.

Comments

1

You need to create a v-model and point the current passenger that you want to submit to that v-model.

export default {
  data() {
  return {
    passengerModal : {}
  

Then, there will be a submit button on each passenger correct? On your submit button you can use

<button @click="passengerModal = passenger; submitThisPassenger()>Current passenger</button>

3 Comments

actually there is one button for all passengers and i must submit all of them with one submit button
Then its more of a backend work, just pass all the passengers as the payload.
i do it, at first create array and pushed with passengers id and with for get each input value clearly thank you @Syazany

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.