Skip to content

Commit 356a249

Browse files
authored
Disable Topic form button until upload completes (#369)
2 parents 77bb3af + 7230f75 commit 356a249

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

app/javascript/controllers/upload_controller.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { Controller } from "@hotwired/stimulus";
22

33
export default class extends Controller {
4-
static targets = ["filesInput", "fileItem", "filesContainer", "hiddenField"];
4+
static targets = [
5+
"filesInput",
6+
"fileItem",
7+
"filesContainer",
8+
"hiddenField",
9+
"submitButton",
10+
"spinner",
11+
];
512

613
uploadFile(event) {
714
event.preventDefault();
815

16+
this.submitButtonTarget.classList.add("disabled");
17+
this.spinnerTarget.classList.remove("d-none");
18+
919
const filesInput = this.filesInputTarget;
1020
let files = Array.from(filesInput.files);
1121

@@ -33,6 +43,9 @@ export default class extends Controller {
3343
filesInput.value = "";
3444
}
3545
});
46+
47+
this.submitButtonTarget.classList.remove("disabled");
48+
this.spinnerTarget.classList.add("d-none");
3649
}
3750

3851
removeFile(event) {

app/views/topics/_form.html.erb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,18 @@
7171
<% end %>
7272

7373
<%= f.file_field :documents, multiple: true, class: "form-control mt-4", id: "documents", data: { upload_target: "filesInput", action: "change->upload#uploadFile" } %>
74-
</div>
75-
<div class="col-12 d-flex justify-content-end">
76-
<%= f.submit class: "btn btn-primary me-1 mb-1" %>
77-
<%= link_to "Cancel", topics_path, class: "btn btn-light-secondary me-1 mb-1" %>
74+
75+
<div class="d-none" data-upload-target="spinner">
76+
<div class="spinner-border spinner-border-sm mt-4" role="status">
77+
<span class="visually-hidden">Uploading in progress...</span>
78+
</div>
79+
<span>Uploading in progress...</span>
80+
</div>
81+
82+
<div class="col-12 d-flex justify-content-end mt-4">
83+
<%= f.submit class: "btn btn-primary me-1 mb-1", data: { upload_target: "submitButton" } %>
84+
<%= link_to "Cancel", topics_path, class: "btn btn-light-secondary me-1 mb-1" %>
85+
</div>
7886
</div>
7987
</div>
8088
</div>

0 commit comments

Comments
 (0)