Using Vue.jsm inertiaJS and Laravel.
I have a VueJS Js page on which i have a form with a table which has multiple rows. I fill each input field on those rows with data coming from the backend.
So, every row has the same fields (account name, description, amount), coming from a number of transactions. So each row represents a transaction. Displaying the transactions work fine.
But, the user may change those values (that’s the purpose), how can i with the help of inertia send the whole form including the rows and their values to the backend for processing and saving into the database?
The inertiaJS docs for forms speaks of using the useForm helper, or reactive. (https://inertiajs.com/forms)
But, as far as i understand it, you have to know each input field up front ánd they need to be named uniquely.
Can someone help me? What i want is for the user to be able to change the values displayed inside of the table row inputs and that that person can click on the save button, which in turn sends the current input values to the backend using inertiaJS.
Any help would be greatly appreciated, i have been plowing through examples on the web, but they all talk about sending input values which are declared inside of the form const. But i have a table with rows. Thanks for any help!
Simplified example code:
<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
import {Head, router, Link} from '@inertiajs/vue3';
import {ref} from "vue";
const props = defineProps({
Transactions: {
type: Object,
required: true
},
Accounts: {
type: Object,
required: true
},
})
const form = reactive({
Account.name: null,
Transaction.description: null,
Transaction.amount: null,
})
function submit() {
router.post('/users', form)
}
</script>
<template>
<AuthenticatedLayout>
<div class="py-12">
<div class="mx-auto max-w-8xls sm:px-6 lg:px-8">
<div class="overflow-scroll bg-white shadow-sm sm:rounded-lg">
<form @submit.prevent="submit">
<table class="table-auto">
<thead>
<tr>
<th class="text-left">Account</th>
<th class="text-left">Description</th>
<th class="text-right">Amount</th>
</tr>
</thead>
<tbody>
<tr v-for="Transaction in Transactions">
<td>
<select v-model="Transaction.account">
<option v-for="Account in Accounts" v-bind:value="Account.id" > {{ Account.name }} </option>
</select>
</td>
<td>
<input type="text" id="fname" name="fname" data-1p-ignore v-model="Transaction.description" class="text-left">
</td>
<td>
<input type="text" id="fname" name="fname" data-1p-ignore v-model="Transaction.amount" class="text-right">
</td>
</tr>
</tbody>
</table>
<button type="submit" class="mb-4 inline-block rounded-md bg-blue-500 px-4 py-3 text-xs font-semibold uppercase tracking-widest text-white shadow-sm">Save</button>
</form>
</div>
</div>
</div>
</AuthenticatedLayout>
</template>