Skip to content

Commit

Permalink
Merge pull request #2564 from bitzesty/staging-cherry-pick-validations
Browse files Browse the repository at this point in the history
[Staging] cherry pick validations
  • Loading branch information
TheDancingClown authored Sep 1, 2023
2 parents 860a660 + abdaa98 commit 491a5b3
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions app/assets/javascripts/frontend/form-validation.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ window.FormValidation =
container.closest("td").find(".govuk-error-message").empty()
else
container.closest(".question-block").find(".govuk-error-message").empty()
container.closest(".question-block").removeClass("govuk-form-group--error")
container.closest(".govuk-form-group--error").removeClass("govuk-form-group--error")

clearAriaDescribedby: (container) ->
Expand Down Expand Up @@ -168,23 +169,24 @@ window.FormValidation =
addSubfieldError: (question, subquestion) ->
questionRef = question.attr("data-question_ref")
input = $(subquestion).find('input,textarea,select').filter(':visible')
label = @extractText(input.attr('id'))
incompleteMessage = "Question #{questionRef} is incomplete. It is required and must be filled in."

if question.hasClass('date-DDMMYYYY')
@addErrorMessage($(subquestion), "#{incompleteMessage} Use the format DD/MM/YYYY.")
else if question.hasClass('date-MMYYYY')
@addErrorMessage($(subquestion), "#{incompleteMessage} Use the format MM/YYYY.")
else if question.hasClass('date-YYYY')
@addErrorMessage($(subquestion), "#{incompleteMessage} Use the format YYYY.")
else if input.hasClass("autocomplete__input")
@addErrorMessage($(subquestion), "Question #{questionRef} is incomplete. #{label} is required and an option must be selected from the following dropdown list.")
else
if question.find(".js-financial-year-latest").length
#avoid duplicate errors for financial year questions
return
if input.length
label = @extractText(input.attr('id'))
incompleteMessage = "Question #{questionRef} is incomplete. It is required and must be filled in."

if question.hasClass('date-DDMMYYYY')
@addErrorMessage($(subquestion), "#{incompleteMessage} Use the format DD/MM/YYYY.")
else if question.hasClass('date-MMYYYY')
@addErrorMessage($(subquestion), "#{incompleteMessage} Use the format MM/YYYY.")
else if question.hasClass('date-YYYY')
@addErrorMessage($(subquestion), "#{incompleteMessage} Use the format YYYY.")
else if input.hasClass("autocomplete__input")
@addErrorMessage($(subquestion), "Question #{questionRef} is incomplete. #{label} is required and an option must be selected from the following dropdown list.")
else
@addErrorMessage($(subquestion), "Question #{questionRef} is incomplete. #{label} is required and must be filled in.")
if question.find(".js-financial-year-latest").length
#avoid duplicate errors for financial year questions
return
else
@addErrorMessage($(subquestion), "Question #{questionRef} is incomplete. #{label} is required and must be filled in.")

addQuestionError: (question) ->
questionRef = question.attr("data-question_ref")
Expand Down

0 comments on commit 491a5b3

Please sign in to comment.