Submit multiple forms in repeat with flow

I have a repeat (a table) with a form

I would like to be able to submit all one after another.… So when one ends the next one starts submitting. I thought the easiest way would be to build a flow for that but there doesn’t seem to be a way to simply do a Repeat or a While is there?

I can set a dynamic id to the forms with dmx-bind:id="exportToPresta{{$index}}" but I can’t reference them with flow, can I?

It’s important for me that the forms are submitted in turns because submitting all at once (with e.g javascript) will overload the server… So I figured I’d move the process to the client side and maybe have a like a dialog box showing progress…

Don’t forget you already have this capability natively within Wappler. Multiple Inserts/Updates are contained within the Database Actions in Server Connect. Removes a lot of the headaches.

Thanks for your reply. Sadly I cannot use server connect for the whole process. Each of those forms triggers an action that does few API requests to other servers and does a file upload - not just a database insert/update.
On average it takes up to 10 seconds. I can’t set the script timeout to more than 1 minute that why I need to do each ome saparately and not just all at once.
Submitting forms one by one seems like the best way to achieve this but I’m not sure if there is a ‘Wappler way’ of doing it…

So is this at all possible?

It is possible. I have achieved it before by using an array/data store that contains each of the items you need to process (a bit like a shopping cart). Add an additional field to the array for ‘processed’.

In a flow you can use a while step to loop through the array where processed == 0 sending each to a server connect. On done of the server connect you can return a value that indicates whether it was successful (e.g. -1 for not , 1 for successful) which you then put in the corresponding array to mark it as complete and take it out of the loop.

On the page, you can show progress by using a repeat of the array e.g. showing a green tick where processed is 1 and a red cross for where it is -1

1 Like

That sounds like a great idea! Thanks!

However I encountered a bit of a problem…

So if I understand it right the method involves - first getting all the data I need into the datastore and then I can iterate through all of it in a flow and submit it in separate forms (exactly how I want).

The problem I’m having is getting the data that’s in forms (i.e. the fields that the user can input)…
I setup a table based on the data inside the datastore just so I can see if it works properly.
I created an insert based on the same source the table is
image

getting the data from that source is trivial but how to grab the data from the generated form fields?

I tried tableRepeat7[$index].exportToPresta.exportPrice.value and it doesn’t work
Actually the expression doesn’t work at all. Even if I target a specific repeat with tableRepeat7[0].exportToPresta.exportPrice.value

When making a change, does the user click a button to save the new value or should it happen any time the input is updated?

Whichever you choose, use a dynamic event and perform an update/upsert to the datastore.
For the Which Records part link the auctionid
For the New Values link the price

It would help to see the code for your form (table)

You will probably find it will be something like:

dmx-on:click="datastore1.upsert({auctionid: auctionid},{price: exportprice.value})"

actually they are going to be prefilled with default prices from the database and only some will require adjustments - that’s why I was looking for a way to insert them all at once but now that I think of it, the datastore can have those same default values and only update those that are modified - the way you suggested. I guess it will be better if the dynamic action happens on update.
This upsert action is way more useful than I thought it would be! It’s great I can use other values than the ID for the updates!

1 Like