Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production release #2603

Merged
merged 8 commits into from
Sep 12, 2023
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -698,7 +698,7 @@ window.FormValidation =
totalOverseasTradePercentage += parseFloat($(this).val())
else
missingOverseasTradeValue = true
if totalOverseasTradePercentage != 100
if totalOverseasTradePercentage.toFixed(2) != (100).toFixed(2)
@logThis(question, "validateGoodsServicesPercentage", "% of your total overseas trade should add up to 100")
@appendMessage(question, "% of your total overseas trade should add up to 100")
@addErrorClass(question)
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: 1 addition & 1 deletion app/views/qae_form/confirm.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ h1.govuk-heading-xl Confirmation of submission
p.govuk-body All winning individuals and their nominators attend Buckingham Palace reception hosted by His Majesty The King.

- else
h3.govuk-heading-m 12 September #{@year - 1}
h3.govuk-heading-m #{submission_deadline.trigger_at.strftime("%d %B %Y")}

p.govuk-body Application period closes

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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def errors

total = 0
question.answers["trade_goods_and_services_explanations"]&.each do |product|
total += product["total_overseas_trade"].to_i
total += product["total_overseas_trade"].to_f.round(2)
end
if total != 100
result[question.key] ||= {}
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
Loading