From 5c999300b54a8a37f92a09a3ce2c2fa63d5df5e1 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Mon, 23 Jul 2018 12:16:52 +0200 Subject: [PATCH] Fix avatar upload validators [SCI-2253] --- app/assets/javascripts/sitewide/form_validators.js.erb | 6 ++++-- app/assets/javascripts/users/registrations/edit.js | 4 ++-- app/views/users/registrations/edit.html.erb | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/sitewide/form_validators.js.erb b/app/assets/javascripts/sitewide/form_validators.js.erb index 96e5e595a..b777e0928 100644 --- a/app/assets/javascripts/sitewide/form_validators.js.erb +++ b/app/assets/javascripts/sitewide/form_validators.js.erb @@ -111,8 +111,10 @@ function filesValidator(ev, fileInputs, fileTypeEnum, canBeEmpty) { var filesValid = true; if (fileInputs.length) { var filesPresentValid = canBeEmpty || filesPresentValidator(ev, fileInputs); - var filesSizeValid = filesSizeValidator(ev, fileInputs, fileTypeEnum); - + var filesSizeValid = false; + if (filesPresentValid) { + filesSizeValid = filesSizeValidator(ev, fileInputs, fileTypeEnum); + } // File spoof check is done on server-side only filesValid = filesPresentValid && filesSizeValid; } diff --git a/app/assets/javascripts/users/registrations/edit.js b/app/assets/javascripts/users/registrations/edit.js index 5d9afa71f..44841cbe9 100644 --- a/app/assets/javascripts/users/registrations/edit.js +++ b/app/assets/javascripts/users/registrations/edit.js @@ -68,7 +68,7 @@ $(this).renderFormErrors('user', data.responseJSON); }); - function processFile(ev) { + $('#user-avatar-field :submit').click(function(ev) { var $form = $(ev.target.form); var $fileInput = $form.find('input[type=file]'); $form.clearFormErrors(); @@ -77,5 +77,5 @@ // Local file uploading animateSpinner(); } - } + }); }()); diff --git a/app/views/users/registrations/edit.html.erb b/app/views/users/registrations/edit.html.erb index c9014afd1..b14bffedd 100644 --- a/app/views/users/registrations/edit.html.erb +++ b/app/views/users/registrations/edit.html.erb @@ -49,7 +49,7 @@
<%=t "general.cancel" %> - <%= f.submit t("users.registrations.edit.avatar_submit"), class: 'btn btn-success', onclick: "processFile(event);" %> + <%= f.submit t("users.registrations.edit.avatar_submit"), class: 'btn btn-success' %>