Skip to content

Commit

Permalink
No submit if no photo is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
tclaus committed Sep 14, 2021
1 parent 676834b commit e1c57ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
23 changes: 19 additions & 4 deletions app/assets/javascripts/archive-uploader.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
const profileFileBtn = document.getElementById("profile-file-btn");
const profileFileButton = document.getElementById("profile-file-btn");

const profileFileChosen = document.getElementById("profile-file-chosen");

profileFileBtn.addEventListener("change", function() {
profileFileButton.addEventListener("change", function() {
profileFileChosen.textContent = this.files[0].name;
checkProfileUploadButton();
});

const photosFileBtn = document.getElementById("photos-file-btn");
const photosFileButton = document.getElementById("photos-file-btn");

const photosFileChosen = document.getElementById("photos-file-chosen");

photosFileBtn.addEventListener("change", function() {
photosFileButton.addEventListener("change", function() {
photosFileChosen.textContent = this.files[0].name;
checkProfileUploadButton();
});

const checkProfileUploadButton = function() {
let photo_files = $("#profile-file-btn")[0].files;
let profile_files = $("#photos-file-btn")[0].files;

if ((photo_files.size + profile_files.size) === 0)
{
$("#upload_profile_files").attr('disabled', 'disabled');
} else {
$("#upload_profile_files").removeAttr('disabled');
}

}
5 changes: 4 additions & 1 deletion app/views/users/_import_account_modal.haml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
.clearfix
.btn.btn-default{data: {dismiss: "modal"}}
= t("users.import_modal.cancel")
= f.submit t("users.import_modal.start_import"), class: "btn btn-primary.pull-right", id: "change_email_preferences"
= f.submit t("users.import_modal.start_import"),
class: "btn btn-primary.pull-right",
id: "upload_profile_files",
disabled: true
= javascript_include_tag "archive-uploader"

0 comments on commit e1c57ca

Please sign in to comment.