Skip to content

Commit

Permalink
Hide file upload input after successful upload. Fix js & non-js valid…
Browse files Browse the repository at this point in the history
…ation for support letter attachments.
  • Loading branch information
DaniBitZesty committed Aug 28, 2024
1 parent eecc745 commit 05118e0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ window.SupportLetters =
textContainer.find('.flex').html('<p class="govuk-body">' + filename + '</p>')
hiddenInput = $("<input class='js-support-letter-attachment-id' type='hidden' name='#{$el.attr("name")}' value='#{data.result['id']}' />")
parent.append(hiddenInput)
parent.find('.js-support-letter-attachment').addClass('govuk-!-display-none')
SupportLetters.autosave()
SupportLetters.submit(e)

Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/frontend/form-validation.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ window.FormValidation =
return question.find("input[type='checkbox']").filter(":checked").length

if @isSupportLetterAttachment(question)
return question.find(".js-support-letter-attachment-id").val().toString().trim().length
return (question.find(".js-support-letter-attachment-id").val() || '').toString().trim().length

validateRequiredQuestion: (question) ->
# if it's a conditional question, but condition was not satisfied
Expand Down
9 changes: 5 additions & 4 deletions app/views/form/support_letters/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@
' If you upload the wrong file, click the 'Remove' link next to the file name to delete it. The file upload button will reappear, allowing you to select the correct file.

= ff.simple_fields_for :support_letter_attachment, (ff.object.support_letter_attachment || ff.object.build_support_letter_attachment) do |fff|
- if ff.object.support_letter_attachment.present?

- if ff.object.support_letter_attachment.id.present?
p.govuk-body.support-letter-attachment-container class="govuk-!-font-size-19"
= render "shared/attachment_with_virus_check_status", item: fff.object, mount_name: :attachment
- if ff.object.support_letter_attachment.id.present?
= link_to 'Remove', form_form_answer_support_letter_support_letter_attachment_path(@form_answer, ff.object, ff.object.support_letter_attachment), method: :delete, class: 'govuk-link non-js-remove-support-letter-attachment govuk-!-font-size-19'

= fff.input :attachment_cache, as: :hidden
= fff.input :attachment_cache, as: :hidden

= fff.input :form_answer_id, as: :hidden, input_html: { value: @form_answer.id }
= fff.input :user_id, as: :hidden, input_html: { value: current_user.id }
= fff.input :form_answer_id, as: :hidden, input_html: { value: @form_answer.id }
= fff.input :user_id, as: :hidden, input_html: { value: current_user.id }

- unless fff.object.id.present?
= fff.input :attachment, as: :file, label: false, input_html: { class: "form-control" }, wrapper_html: { style: "margin-bottom: -1rem;" }
3 changes: 1 addition & 2 deletions app/views/qae_form/_supporter_fields.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ li.borderless[class=class_names("js-add-example", "js-support-letter-received" =
' If you upload the wrong file, click the 'Remove' link next to the file name to delete it. The file upload button will reappear, allowing you to select the correct file.
span.govuk-error-message
input class="js-support-letter-field js-trigger-autosave js-support-letter-attachment govuk-input medium #{'govuk-!-display-none' if supporter['letter_of_support'].present?}" name="form[#{question.key}][#{index}][letter_of_support]" id="form[#{question.key}][#{index}][letter_of_support]" type='file' *possible_read_only_ops(question.step.opts[:id])
- if supporter['letter_of_support'].present?
= render "support_letters/attachment", question: question, index: index, supporter: supporter, attachment_id: supporter['letter_of_support']
= render "support_letters/attachment", question: question, index: index, supporter: supporter, attachment_id: supporter['letter_of_support']
2 changes: 1 addition & 1 deletion app/views/support_letters/_attachment.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- file = support_letter_attachments[attachment_id.to_i]

.support-letter-attachment-container
.support-letter-attachment-container class="#{'govuk-!-display-none' unless attachment_id.present?}"
.flex
.support-letter-attachment-filename class="govuk-!-font-size-19"
= render "shared/attachment_with_virus_check_status", item: file, mount_name: :attachment
Expand Down

0 comments on commit 05118e0

Please sign in to comment.