diff --git a/app/assets/javascripts/exercises.js b/app/assets/javascripts/exercises.js index ba5225829..8ebcc88a1 100644 --- a/app/assets/javascripts/exercises.js +++ b/app/assets/javascripts/exercises.js @@ -87,12 +87,12 @@ $(document).on('turbolinks:load', function () { // validate fileUrl const matches = fileUrl.match(/files\/(\d+)/); if (matches) { - // select the file form based on the delete button - const fileForm = $(`*[data-file-url="${fileUrl}"]`).parent().parent().parent(); - fileForm.remove(); - - // now remove the hidden input representing the file const fileId = matches[1]; + + $(`#file-form-${fileId}`).remove(); + + // The remaining hidden input field associated with the + // deleted file needs to be removed. const input = $(`input[type="hidden"][value="${fileId}"]`) input.remove() } diff --git a/app/views/exercises/_file_form.html.slim b/app/views/exercises/_file_form.html.slim index 00a24021d..b32acc290 100644 --- a/app/views/exercises/_file_form.html.slim +++ b/app/views/exercises/_file_form.html.slim @@ -1,6 +1,6 @@ - id = f.object.id -li.card.mt-2 +li.card.mt-2 id="file-form-#{id}" .card-header#heading role='tab' - collapsed_class = f.index == 'index' ? nil : 'collapsed' - aria_expanded = f.index == 'index' ? 'true' : 'false'