diff --git a/app/controllers/template_documents_controller.rb b/app/controllers/template_documents_controller.rb index f70e9ecf..3d89035d 100644 --- a/app/controllers/template_documents_controller.rb +++ b/app/controllers/template_documents_controller.rb @@ -4,7 +4,9 @@ class TemplateDocumentsController < ApplicationController load_and_authorize_resource :template def create - return head :unprocessable_entity if params[:blobs].blank? && params[:files].blank? + if params[:blobs].blank? && params[:files].blank? + return render json: { error: 'File is missing' }, status: :unprocessable_entity + end old_fields_hash = @template.fields.hash diff --git a/app/javascript/elements/download_button.js b/app/javascript/elements/download_button.js index 407f2fc4..1332d2ec 100644 --- a/app/javascript/elements/download_button.js +++ b/app/javascript/elements/download_button.js @@ -17,13 +17,18 @@ export default targetable(class extends HTMLElement { this.toggleState() - fetch(this.dataset.src).then((response) => response.json()).then((urls) => { - const isSafariIos = /iPhone|iPad|iPod/i.test(navigator.userAgent) - - if (isSafariIos && urls.length > 1) { - this.downloadSafariIos(urls) + fetch(this.dataset.src).then(async (response) => { + if (response.ok) { + const urls = await response.json() + const isSafariIos = /iPhone|iPad|iPod/i.test(navigator.userAgent) + + if (isSafariIos && urls.length > 1) { + this.downloadSafariIos(urls) + } else { + this.downloadUrls(urls) + } } else { - this.downloadUrls(urls) + alert('Failed to download files') } }) } diff --git a/app/javascript/submission_form/completed.vue b/app/javascript/submission_form/completed.vue index c863f3e9..fd970c45 100644 --- a/app/javascript/submission_form/completed.vue +++ b/app/javascript/submission_form/completed.vue @@ -197,13 +197,18 @@ export default { download () { this.isDownloading = true - fetch(this.baseUrl + `/submitters/${this.submitterSlug}/download`).then((response) => response.json()).then((urls) => { - const isSafariIos = /iPhone|iPad|iPod/i.test(navigator.userAgent) + fetch(this.baseUrl + `/submitters/${this.submitterSlug}/download`).then(async (response) => { + if (response.ok) { + const urls = await response.json() + const isSafariIos = /iPhone|iPad|iPod/i.test(navigator.userAgent) - if (isSafariIos && urls.length > 1) { - this.downloadSafariIos(urls) + if (isSafariIos && urls.length > 1) { + this.downloadSafariIos(urls) + } else { + this.downloadUrls(urls) + } } else { - this.downloadUrls(urls) + alert('Failed to download files') } }) }, diff --git a/app/javascript/submission_form/form.vue b/app/javascript/submission_form/form.vue index bea20471..c8250167 100644 --- a/app/javascript/submission_form/form.vue +++ b/app/javascript/submission_form/form.vue @@ -972,14 +972,16 @@ export default { this.$nextTick(() => { this.recalculateButtonDisabledKey = Math.random() - if (scrollToArea) { - this.scrollIntoField(step[0]) + if (!this.isCompleted) { + if (scrollToArea) { + this.scrollIntoField(step[0]) - this.$refs.form.querySelector('input[type="date"], input[type="number"], input[type="text"], select')?.focus() - } + this.$refs.form.querySelector('input[type="date"], input[type="number"], input[type="text"], select')?.focus() + } - if (clickUpload && !this.values[this.currentField.uuid] && ['file', 'image'].includes(this.currentField.type)) { - this.$refs.form.querySelector('input[type="file"]')?.click() + if (clickUpload && !this.values[this.currentField.uuid] && ['file', 'image'].includes(this.currentField.type)) { + this.$refs.form.querySelector('input[type="file"]')?.click() + } } }) },