Skip to content

Commit ccb652e

Browse files
committed
Fixes #259 Reflect file deletion by removing the whole entry
Remove the whole file element from the exercise form when a file is deleted.
1 parent 2a4d9cf commit ccb652e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

app/assets/javascripts/exercises.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ $(document).on('turbolinks:load', function () {
8787
// validate fileUrl
8888
const matches = fileUrl.match(/files\/(\d+)/);
8989
if (matches) {
90-
// select the file form based on the delete button
91-
const fileForm = $(`*[data-file-url="${fileUrl}"]`).parent().parent().parent();
92-
fileForm.remove();
93-
94-
// now remove the hidden input representing the file
9590
const fileId = matches[1];
91+
92+
$(`#file-form-${fileId}`).remove();
93+
94+
// The remaining hidden input field associated with the
95+
// deleted file needs to be removed.
9696
const input = $(`input[type="hidden"][value="${fileId}"]`)
9797
input.remove()
9898
}

app/views/exercises/_file_form.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- id = f.object.id
22

3-
li.card.mt-2
3+
li.card.mt-2 id="file-form-#{id}"
44
.card-header#heading role='tab'
55
- collapsed_class = f.index == 'index' ? nil : 'collapsed'
66
- aria_expanded = f.index == 'index' ? 'true' : 'false'

0 commit comments

Comments
 (0)