Get a total of input fields inside a repeat table

i have a simple table that is showing records from a database query, (name 1 and name 2) are coming from a database… i dont want to enter the numbers on the form submit because i dont want them saved on the database, instead i want to manually enter the numbers on the inputs which are repeated within the row… how can i calculate the total of the numbers entered in the repeated inputs…

Hello!
I don’t understand very well what do you need

If you don’t declare them under the post input tree and the insert step (server connect) they won’t be saved on the table

there is a form that send the names (name 1, name 2) to database… then on the table i bind the name the left cel, on the other cell i inserted that input… so basically the table display the names one the left, then on the right is the inputs… is it possible to get the total of the values typed in the input?

You obviously want to know the total of all the inputs before submit… That’s what I understand.

Anyway, a fast workaround that comes to mind is:
Client-side

  • Add a variable before the repeat , eg var_Inputs, and set its value to 0

  • Inside the repeat, attach on the input an update event and set update the value of var_input by adding the input.value.
    `
    dmx-on:updated= “var_Inputs.setValue(var_Inputs.value.toNumber()+(value.toNumber()&gt=0?value.toNumber():0))”

  • After the repeat (or anywhere in your page) you call the var_Inputs.value and get the total of all inputs.

That’s it…

** I checked for the content of the input in order not to break the calculation if it is null
`

i followed this, and im able to get a total from the repeat… now the problem is when i delete a row the total doesnt update… code dmx-on:updated=“var_inputs.setValue((var_inputs.value.toNumber() + value.toNumber()))”

Actually what I suggested is not correct…
My apologies for this fast response buddy!
Everytime the input is updated the total will be recalculated and so… not the total but more.

But you can add an array instead of the variable and inside the update event add array at $index the input value

EDIT: not insert at $index but replace itam at $index

Capture
im getting this on the total input. what did i miss, how do i get the value from the total input?

sorry i got it, it works… but how can i solve the problem of the total input not updating after deleting the row

did you use sum() formatter for the total?

Can you screenshot what you have now?

yes i did used the sum, its working perfectlt … so there is no way i can make the total input update instatly when deleting a row… let me record a video

You need and a remove item at when row is deleted

<dmx-array id="arr1"></dmx-array>

            <div is="dmx-form-repeat" id="formRepeat1" dmx-bind:items="srvc_wishList.data.qr_getWishlistProds">

                <div class="row">

                    <div class="col-1 text-center">

                        <button id="btn1" class="btn btn-danger" dmx-on:click="arr1.removeAt($index);formRepeat1.remove($index)">Delete</button>

                    </div>

                    <div class="col-2" dmx-text="wsh_id"></div>

                    <div class="col" dmx-text="wsh_name"></div>

                    <div class="col">

                        <input id="text1" name="text1" type="text" class="form-control" dmx-on:updated="arr1.replaceAt($index,value.toNumber())">

                    </div>

                </div>

            </div>

            <div class="row mt-3">

                <p class="text-muted" dmx-text="'TOTAL: '+arr1.items.sum()">With faded secondary text</p>

            </div>

Works perfect, just tested it

I tested it and works fine!!
you must missed a step buddy…
paste your code here
or screenshot

woorey i got it right… works perfectly how i want it… thanks a million times :grin: :grin:

1 Like