Added async submit function..
This commit is contained in:
		
							
								
								
									
										5
									
								
								resources/assets/js/mixins/global.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								resources/assets/js/mixins/global.js
									
									
									
									
										vendored
									
									
								
							@@ -119,6 +119,11 @@ export default {
 | 
			
		||||
            this.form.submit();
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        // Form Async Submit
 | 
			
		||||
        async onAsyncSubmit() {
 | 
			
		||||
            await this.form.asyncSubmit();
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        onHandleFileUpload(key, event) {
 | 
			
		||||
            this.form[key] = '';
 | 
			
		||||
            this.form[key] = event.target.files[0];
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										44
									
								
								resources/assets/js/plugins/form.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										44
									
								
								resources/assets/js/plugins/form.js
									
									
									
									
										vendored
									
									
								
							@@ -409,6 +409,50 @@ export default class Form {
 | 
			
		||||
        .catch(this.onFail.bind(this));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async asyncSubmit() {
 | 
			
		||||
        FormData.prototype.appendRecursive = function(data, wrapper = null) {  
 | 
			
		||||
            for (var name in data) {
 | 
			
		||||
                if (name == "previewElement" || name == "previewTemplate") {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (wrapper) {
 | 
			
		||||
                    if ((typeof data[name] == 'object' || Array.isArray(data[name])) && ((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' || Array.isArray(data[name])) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) {
 | 
			
		||||
                        this.appendRecursive(data[name], name);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        this.append(name, data[name]);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        this.loading = true;
 | 
			
		||||
 | 
			
		||||
        let data = this.data();
 | 
			
		||||
 | 
			
		||||
        let form_data = new FormData();
 | 
			
		||||
        form_data.appendRecursive(data);
 | 
			
		||||
 | 
			
		||||
        await window.axios({
 | 
			
		||||
            method: this.method,
 | 
			
		||||
            url: this.action,
 | 
			
		||||
            data: form_data,
 | 
			
		||||
            headers: {
 | 
			
		||||
                'X-CSRF-TOKEN': window.Laravel.csrfToken,
 | 
			
		||||
                'X-Requested-With': 'XMLHttpRequest',
 | 
			
		||||
                'Content-Type': 'multipart/form-data'
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
        .then(this.onSuccess.bind(this))
 | 
			
		||||
        .catch(this.onFail.bind(this));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    onSuccess(response) {
 | 
			
		||||
        this.errors.clear();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user