Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support file and array uploads #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,24 @@ class Form {
* Fetch all relevant data for the form.
*/
data() {
let data = {};

let data = new FormData();

for (let property in this.originalData) {
data[property] = this[property];

if (Array.isArray(this[property])) {
var tmp_array = this[property];
for (var i = 0; i < tmp_array.length; i++) {
// use append instead of set, otherwise
// field[] would be overwritten
// https://developer.mozilla.org/en-US/docs/Web/API/FormData/append
data.append(property + '[]', tmp_array[i]);
}
continue;
}

// https://developer.mozilla.org/en-US/docs/Web/API/FormData/set
data.set(property, this[property]);
}

return data;
Expand Down