Menu

Line-Item Forms with Inertia and React: Dynamic Rows, Nested Errors and Live Totals
📰

Line-Item Forms with Inertia and React: Dynamic Rows, Nested Errors and Live Totals

DEV Community: react·Tuğrul Yıldırım·2 days ago
#n4T3XnTF
#devtoreact#devto#dev#lines#line
Reading 0:00
15s threshold

Every business app has one form that is harder than all the others: the one with line items. A quote, a purchase order, an invoice, a stock transfer. The header is easy (customer, date, currency). The rows are where it gets messy: users add and remove lines, change a quantity and expect the total to update instantly, and then the server rejects line 3 and the error shows up next to line 4.

I have rebuilt this form more times than I would like to admit. This post is the version I now start from, using Laravel, Inertia and React: one useForm holding the header and the lines, stable row keys, validation errors that land on the right row, live totals that never touch floats, and a server that recalculates everything anyway.

The examples use Inertia's React adapter ( @inertiajs/react , v3 docs) and Laravel 13's validator.

The problem: rows are not fields

A flat form maps one input to one key. A line-item form maps inputs to positions in an array, and positions change.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.