Access Form Repeat data

Love the new Form Repeat, but I’m not seeing how to access that data outside of the repeat.

For example, on a quote form with a list of details, I’d like to get the sum of the amounts within the form repeat in order to display a total.

Have I missed this?

Yes I was wondering about this, as well! I have tried things like:

                                    {{formRepeat1.amountgrams.value}}
                                    {{formRepeat1.items.sum(amountgrams.value)}}
                                    {{formRepeat1.sum(amountgrams.value)}}
                                    {{formRepeat1.items.sum('amountgrams.value')}}
                                    {{formRepeat1.sum('amountgrams.value')}}

As inspired by How to calculate a totals field in a form with 20 currency input fields?

But no dice…

Did you have any luck with this?

I selected the desired inputs using JavaScript, calculated the result, and then set a variable ion Wappler.

You would be the absolute end boss if you could share some example code! :robot:

Too bad this is not (yet!) available in the Wappler UI…

I created a function to be called to update a total amount:

It gets all inputs with a specific class, and performs the calc, and then sets a value in the dmx world.

function findTotal() {
    var arr = document.getElementsByClassName('quote_detail_amount');

    var tot = 0;
    for (var i = 0; i < arr.length; i++) {
        if (parseFloat(arr[i].value))
            tot += parseFloat(arr[i].value);
    }
    dmx.parse("content.quote_total_amount.setValue(" + tot + ")");

}

The following is the input inside the repat, that I want to use in the function calc, so I add a class to it and add the onupdated attribute:

<input id="inp_quote_detail_amount" name="" type="tel" class="form-control form-control-sm quote_detail_amount" dmx-bind:value="(inp_quote_detail_cost.value.toNumber() + inp_quote_detail_margin.value.toNumber())" readonly="true" disabled="true" onupdated="findTotal()">

And then I display the total using the dmx var:

<p class=" mb-0" dmx-text="quote_total_amount.value.formatCurrency('$', '.', ',', 2)"></p>
1 Like

You are the true end boss, @mebeingken! It works perfectly!! Proves once again that, Wappler’s amazing UI aside, one should actually learn proper js…

As a token of gratefulness I give you an image of one of my dearest computer memories:

Thanks again! :grin: :+1:

1 Like

For anyone using @mebeingken’s code to run the sum total script, I suggest you think about running the script from a page flow, so you can add debounce (if desired).

As described here:

Adding to this request — knowing if the form repeat hasItems, would also be nice.

Was just about to post to ask if accessing form repeat data was possible… Will this be implemented soon? Otherwise I’ll have to do what I wanted with a normal repeat / table

Bump

1 Like

Can I also add to this request that nested form repeats become a thing. When the input names are being generated, it only generates from the current repeat and not from the parent. (I’ve tried to override this with binding a custom name, but this does not work) E.g.

– ParentRepeat[0][ChildRepeat][input]

Use case is for creating a family file. Creating multiple parents with multiple phone numbers and email addresses each.

I’ve made a small update that should make the items property available, just like with the standard repeat component.

dmxFormRepeat.zip (1.6 KB)

1 Like

… late to the party, but link to the ‘form repeat’ documentation please :relaxed: think I missed something…

Added in Wappler 5.0.3

This topic was automatically closed after 28 hours. New replies are no longer allowed.