From 335fbeec012cb10af5dd3e1fbab3b42f81dde6c3 Mon Sep 17 00:00:00 2001 From: DaniBitZesty <84323332+DaniBitZesty@users.noreply.github.com> Date: Tue, 8 Aug 2023 09:08:56 +0100 Subject: [PATCH] Adds non-js validation for matrix cells --- .tool-versions | 1 - app/views/qae_form/_matrix_question.html.slim | 5 +++++ .../v2024/social_mobility/social_mobility_step3.rb | 1 + forms/qae_form_builder/matrix_question.rb | 9 +++++---- 4 files changed, 11 insertions(+), 5 deletions(-) delete mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index f2a971aa75..0000000000 --- a/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -ruby 3.2.2 diff --git a/app/views/qae_form/_matrix_question.html.slim b/app/views/qae_form/_matrix_question.html.slim index 87df46c641..bfb0b96869 100644 --- a/app/views/qae_form/_matrix_question.html.slim +++ b/app/views/qae_form/_matrix_question.html.slim @@ -18,3 +18,8 @@ table.matrix-question-table.govuk-table class="#{'auto-totals-column' if questio = "#{y_heading.label} numbers for #{x_heading.label}" input.js-trigger-autosave.matrix-question-input.govuk-input type="number" data-required-row-parent=question.required_row_parent min="0" step="1" name=question.input_name(suffix: "#{x_heading.key}_#{y_heading.key}") value=question.input_value(suffix: "#{x_heading.key}_#{y_heading.key}") id=question.input_name(suffix: "#{x_heading.key}_#{y_heading.key}") autocomplete="off" *possible_read_only_ops aria-describedby=(@form_answer.validator_errors && @form_answer.validator_errors[question.hash_key] ? "error_for_#{question.key}" : nil ) span.govuk-error-message aria-live="polite" + - if @form_answer.validator_errors && @form_answer.validator_errors["#{question.hash_key}_#{x_heading.key}_#{y_heading.key}"].present? + | Required + span.govuk-visually-hidden id="error_for_#{question.key}" + | Error: + =< @form_answer.validator_errors[question.hash_key] diff --git a/forms/award_years/v2024/social_mobility/social_mobility_step3.rb b/forms/award_years/v2024/social_mobility/social_mobility_step3.rb index a005b46379..b10f860ca5 100644 --- a/forms/award_years/v2024/social_mobility/social_mobility_step3.rb +++ b/forms/award_years/v2024/social_mobility/social_mobility_step3.rb @@ -543,6 +543,7 @@ def mobility_step3 classes "sub-question question-matrix" ref "C 5.2" required + required_rows :initiative_activities context %(
When answering this question, please refer to the guidance under C5.
) diff --git a/forms/qae_form_builder/matrix_question.rb b/forms/qae_form_builder/matrix_question.rb index d9b788fd37..0a5435b3fd 100644 --- a/forms/qae_form_builder/matrix_question.rb +++ b/forms/qae_form_builder/matrix_question.rb @@ -2,15 +2,16 @@ class QaeFormBuilder class MatrixQuestionValidator < QuestionValidator def errors result = super - if question.required? question.y_headings.each do |y_heading| question.x_headings.each do |x_heading| suffix = "#{x_heading.key}_#{y_heading.key}" - if !question.input_value(suffix: suffix).present? && question.required_rows.include?(y_heading.key) - result[question.hash_key(suffix: suffix)] ||= "" - result[question.hash_key(suffix: suffix)] << "Required" + if !question.input_value(suffix: suffix).present? + if (question.required_row_parent && question.required_rows.include?(y_heading.key)) || !question.required_row_parent + result[question.hash_key(suffix: suffix)] ||= "" + result[question.hash_key(suffix: suffix)] << "Required" + end end end end