I have a form that includes a dynamic table (nx2) that has inputs in every row. When I submit the form, I need to save all those inputs' values in an array. It should look something like: [['M',10],['S',10],.......]. I'm not finding a way to achieve this, I've seen I have to differentiate each input but I don't know how to access the value later.
This is my code for the table:
<table class="table-size-qty">
<thead>
<tr>
<th scope="col">Size</th>
<th scope="col">Qty</th>
</tr>
{rows.map((r) => (
<tr>
<td><input className="no-style" name={'size'+r} type="text"></input></td>
<td><input className="no-style" name={'qty'+r} type="number"></input></td>
</tr>
))}
</thead>
</table>
<button type='button' class="buttonAddRow" onClick={addRow}>Add row</button>
On every click it adds a row trough the addRow() method:
const addRow = () => {
setRows([...rows, rows.length]);
}
Thank you very much in advance!