From 20a082ae8e6e461993da5a2840c3b9eb954ef742 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Mon, 21 Jul 2025 16:26:08 +0300 Subject: [PATCH] adjust image field validation --- app/javascript/submission_form/dropzone.vue | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/javascript/submission_form/dropzone.vue b/app/javascript/submission_form/dropzone.vue index 29ec6798..89e01b3b 100644 --- a/app/javascript/submission_form/dropzone.vue +++ b/app/javascript/submission_form/dropzone.vue @@ -112,11 +112,23 @@ export default { onSelectFiles (e) { e.preventDefault() - this.uploadFiles(this.$refs.input.files).then(() => { - if (this.$refs.input) { - this.$refs.input.value = '' + const files = Array.from(this.$refs.input.files).filter((f) => { + if (this.accept === 'image/*') { + return f.type.startsWith('image') + } else { + return true } }) + + if (this.accept === 'image/*' && !files.length) { + alert(this.t('please_upload_an_image_file')) + } else { + this.uploadFiles(files).then(() => { + if (this.$refs.input) { + this.$refs.input.value = '' + } + }) + } }, async uploadFiles (files) { this.isLoading = true