Skip to content

Commit

Permalink
Adds non-js validation for matrix cells
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniBitZesty committed Aug 8, 2023
1 parent 1579a96 commit 335fbee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 0 additions & 1 deletion .tool-versions

This file was deleted.

5 changes: 5 additions & 0 deletions app/views/qae_form/_matrix_question.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ def mobility_step3
classes "sub-question question-matrix"
ref "C 5.2"
required
required_rows :initiative_activities
context %(
<p>When answering this question, please refer to the guidance under C5.</p>
)
Expand Down
9 changes: 5 additions & 4 deletions forms/qae_form_builder/matrix_question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 335fbee

Please sign in to comment.