Dynamically create Form data

Greetings! I am working with REST API queries and I am interested in dynamical Form Data creation. This is my form
image
And as you can see it could be a few uploaded files inside file input, but REST API allows only static amount of files


So if there are more file it will display only one file and if there are less than 5 files it will show an error. Could you please help me to deal with this issue?

There are a few paths to dealing with the issue you are trying to resolve. The most straightforward would be to have a query for each case you need since it is limited to 5 it isn't too hefty of a task.

Another way would be to build your form data as part of a transformer/jsquery and then send the result regardless of the number of files attached.

I'd say since you know that there will be at least 1 and up to 5 files to process gives you a good framework for developing logic to call upon the right query. A chained ternary operation or a switch/case could work for that:

{{fileDropzone.value.length === 1 ? uploadOneFile.trigger() : fileDropzone.value.length === 2 ? uploadTwoFiles.trigger() : fileDropzone.value.length...}}

Something like this would make sure the right form data is sent with the right number of arguments/inputs.

1 Like

Thank you a lot!

2 Likes