diff --git a/resources/assets/js/views/common/documents.js b/resources/assets/js/views/common/documents.js index f3622d40e..28867d6c6 100644 --- a/resources/assets/js/views/common/documents.js +++ b/resources/assets/js/views/common/documents.js @@ -76,6 +76,7 @@ const app = new Vue({ ',,' ], email_template: false, + minor_form_loading: false } }, @@ -654,20 +655,19 @@ const app = new Vue({ if (response.data.success) { if (response.data.redirect) { this.form.loading = true; - window.location.href = response.data.redirect; } } if (response.data.error) { this.form.loading = false; - + this.form.response = response.data; } }) .catch(error => { this.form.loading = false; - + this.form.onFail(error); this.method_show_html = error.message; @@ -772,7 +772,6 @@ const app = new Vue({ if (response.data.success) { if (response.data.redirect) { this.form.loading = true; - window.location.href = response.data.redirect; } } @@ -946,7 +945,7 @@ const app = new Vue({ let form_html = document.querySelector('form'); if (form_html && form_html.getAttribute('id') == 'document') { - form_html.querySelectorAll('input, textarea, select, ul, li, a, [type="button"]').forEach((element) => { + form_html.querySelectorAll('input, textarea, select, ul, li, a').forEach((element) => { element.addEventListener('click', () => { this.onBeforeUnload(); }); @@ -970,7 +969,18 @@ const app = new Vue({ onSubmitViaSendEmail() { this.form['senddocument'] = true; + this.minor_form_loading = true; + this.onSubmit(); + + this.form.loading = false; + + setTimeout(() => { + if (Object.keys(this.form.errors.errors.length > 0)) { + this.minor_form_loading = false; + return; + } + }, 200); }, }, @@ -1110,6 +1120,6 @@ const app = new Vue({ } this.form.discount = this.form.discount.replace(',', '.'); - }, + } }, }); diff --git a/resources/views/components/documents/form/buttons.blade.php b/resources/views/components/documents/form/buttons.blade.php index 88019dbaf..d8d77b63c 100644 --- a/resources/views/components/documents/form/buttons.blade.php +++ b/resources/views/components/documents/form/buttons.blade.php @@ -8,11 +8,11 @@ id="invoice-send-to" class="relative flex items-center justify-center bg-green hover:bg-green-700 text-white px-6 py-1.5 ltr:ml-2 rtl:mr-2 text-base rounded-lg disabled:bg-green-100" override="class" - ::disabled="form.loading" + ::disabled="minor_form_loading" @click="onSubmitViaSendEmail" > - - + + {{ trans('general.send_to') }}