Merge pull request #1312 from cuneytsenturk/master
Not able to upload files
This commit is contained in:
commit
5114f560a3
39
resources/assets/js/plugins/form.js
vendored
39
resources/assets/js/plugins/form.js
vendored
@ -1,5 +1,4 @@
|
|||||||
import Errors from './error';
|
import Errors from './error';
|
||||||
import axios from "axios";
|
|
||||||
|
|
||||||
export default class Form {
|
export default class Form {
|
||||||
constructor(form_id) {
|
constructor(form_id) {
|
||||||
@ -226,10 +225,10 @@ export default class Form {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
oldSubmit() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
axios({
|
window.axios({
|
||||||
method: this.method,
|
method: this.method,
|
||||||
url: this.action,
|
url: this.action,
|
||||||
data: this.data()
|
data: this.data()
|
||||||
@ -238,25 +237,39 @@ export default class Form {
|
|||||||
.catch(this.onFail.bind(this));
|
.catch(this.onFail.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
submitTest() {
|
submit() {
|
||||||
|
FormData.prototype.appendRecursive = function(data, wrapper = null) {
|
||||||
|
for(var name in data) {
|
||||||
|
if (wrapper) {
|
||||||
|
if ((typeof data[name] == 'object' || data[name].constructor === Array) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) {
|
||||||
|
this.appendRecursive(data[name], wrapper + '[' + name + ']');
|
||||||
|
} else {
|
||||||
|
this.append(wrapper + '[' + name + ']', data[name]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((typeof data[name] == 'object' || data[name].constructor === Array) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) {
|
||||||
|
this.appendRecursive(data[name], name);
|
||||||
|
} else {
|
||||||
|
this.append(name, data[name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
let data = this.data();
|
let data = this.data();
|
||||||
|
|
||||||
let form_data = new FormData();
|
let form_data = new FormData();
|
||||||
|
form_data.appendRecursive(data);
|
||||||
|
|
||||||
for (let key in data) {
|
window.axios({
|
||||||
if ((typeof data[key] != 'object') && (typeof data[key] != 'array') ) {
|
|
||||||
form_data.append(key, data[key]);
|
|
||||||
} else {
|
|
||||||
form_data.append(key, JSON.stringify(data[key]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
axios({
|
|
||||||
method: this.method,
|
method: this.method,
|
||||||
url: this.action,
|
url: this.action,
|
||||||
data: form_data,
|
data: form_data,
|
||||||
headers: {
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': window.Laravel.csrfToken,
|
||||||
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
'Content-Type': 'multipart/form-data'
|
'Content-Type': 'multipart/form-data'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user