Skip to content

Commit

Permalink
Merge pull request #2603 from bitzesty/staging
Browse files Browse the repository at this point in the history
Production release
  • Loading branch information
Lubosky authored Sep 12, 2023
2 parents 9b2996f + f5814f2 commit afeac01
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
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 @@ -376,7 +376,7 @@ window.FormValidation =
else
subqList = subq.closest(".row").find(".span-financial")
subqIndex = subqList.index(subq.closest(".span-financial"))
employeeLimit = 2
employeeLimit = parseInt(subq.attr('min') || 2)

if parseInt(subq.val()) < employeeLimit
@logThis(question, "validateEmployeeMin", "Minimum of #{employeeLimit} employees")
Expand Down
9 changes: 9 additions & 0 deletions app/javascript/packs/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ body.js-enabled {
margin: 0 !important;
}

.govuk-form-group {
input[readonly],
textarea[readonly] {
background-color: rgba(0, 0, 0, 0.03);
color: rgb(84, 84, 84);
cursor: not-allowed;
}
}

.pagination {
@supports (flex-wrap: wrap) {
margin-bottom: 3rem;
Expand Down
4 changes: 4 additions & 0 deletions app/views/qae_form/_by_years_question.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
strong
= "If you had growth in the last #{c.years} years"
.govuk-grid-row
- validatable_years = question.validatable_years_position.present? && (1..c.years).to_a[*question.validatable_years_position]
- (1..c.years).each do |y|
- suffix = "#{y}of#{c.years}"
- minmax_ops = validatable_years ? { min: (y.in?(validatable_years) ? 2 : 0) } : {}
.span-financial.govuk-grid-column-one-third
label.govuk-label class="govuk-!-margin-bottom-0 govuk-!-margin-top-5" for=question.input_name(suffix: "#{y}of#{c.years}")
span.js-year-end.show-default data-year="#{suffix}" data-year-diff="#{::Utils::Diff.calc(c.years, y)}"
Expand All @@ -35,6 +37,7 @@
id=question.input_name(suffix: suffix)
autocomplete="off"
*possible_read_only_ops
*minmax_ops
aria-describedby=(@form_answer.validator_errors && @form_answer.validator_errors[question.hash_key] ? "error_for_#{suffix}" : nil )
]
- else
Expand All @@ -47,6 +50,7 @@
id=question.input_name(suffix: suffix)
autocomplete="off"
*possible_read_only_ops
*minmax_ops
aria-describedby=(@form_answer.validator_errors && @form_answer.validator_errors[question.hash_key] ? "error_for_#{suffix}" : nil )
]
.clear
2 changes: 1 addition & 1 deletion app/views/qae_form/_matrix_question.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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"
disabled=(disabled_row_input || disabled_col_input)
readonly=disabled_input.present?
data-required-row-parent=question.required_row_parent
min="0"
step="1"
Expand Down
2 changes: 2 additions & 0 deletions forms/award_years/v2024/innovation/innovation_step4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def innovation_step4
conditional :financial_year_date_changed, :true

employees_question

validatable_years_position [-2..-1] # validate only last 2 years for employee min. threshold
end

about_section :company_financials, "Company Financials" do
Expand Down
21 changes: 20 additions & 1 deletion forms/qae_form_builder/by_years_question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ def errors
end
end

if question.fields_count && question.validatable_years_position.present?
validatable_years = (1..question.fields_count).to_a[*question.validatable_years_position]

question.active_fields.each.with_index(1) do |suffix, idx|
value = question.input_value(suffix: suffix)
threshold = idx.in?(validatable_years) ? 2 : 0

if value.present? && value.to_i < threshold
result[question.hash_key(suffix: suffix)] ||= ""
result[question.hash_key(suffix: suffix)] << result[question.hash_key(suffix: suffix)] << "Question #{question.ref || question.sub_ref} is invalid. Required minimum is #{threshold} employees."
end
end
end

result
end
end
Expand Down Expand Up @@ -107,6 +121,10 @@ def first_year_min_value(min_value, validation_message)
@q.first_year_min_value = min_value
@q.first_year_validation_message = validation_message
end

def validatable_years_position(values)
@q.validatable_years_position = values
end
end

class ByYearsCondition
Expand All @@ -125,7 +143,8 @@ class ByYearsQuestion < Question
:label,
:employees_question,
:first_year_min_value,
:first_year_validation_message
:first_year_validation_message,
:validatable_years_position

def after_create
@by_year_conditions = []
Expand Down
7 changes: 6 additions & 1 deletion forms/qae_form_builder/one_option_by_years_question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def first_year_min_value(min_value, validation_message)
@q.first_year_min_value = min_value
@q.first_year_validation_message = validation_message
end

def validatable_years_position(values)
@q.validatable_years_position = values
end
end

class OneOptionByYearsCondition
Expand All @@ -76,7 +80,8 @@ class OneOptionByYearsQuestion < Question
:label,
:employees_question,
:first_year_min_value,
:first_year_validation_message
:first_year_validation_message,
:validatable_years_position

end
end

0 comments on commit afeac01

Please sign in to comment.