diff --git a/app/assets/javascripts/frontend/form-validation.js.coffee b/app/assets/javascripts/frontend/form-validation.js.coffee index 6423116e6..6e13747f0 100644 --- a/app/assets/javascripts/frontend/form-validation.js.coffee +++ b/app/assets/javascripts/frontend/form-validation.js.coffee @@ -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") @@ -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) diff --git a/app/javascript/packs/application.scss b/app/javascript/packs/application.scss index 54a182499..349d89ccd 100644 --- a/app/javascript/packs/application.scss +++ b/app/javascript/packs/application.scss @@ -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; diff --git a/app/views/qae_form/_by_years_question.html.slim b/app/views/qae_form/_by_years_question.html.slim index a558438df..6c037a462 100644 --- a/app/views/qae_form/_by_years_question.html.slim +++ b/app/views/qae_form/_by_years_question.html.slim @@ -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)}" @@ -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 @@ -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 diff --git a/app/views/qae_form/_matrix_question.html.slim b/app/views/qae_form/_matrix_question.html.slim index 687e22219..9ffb704b1 100644 --- a/app/views/qae_form/_matrix_question.html.slim +++ b/app/views/qae_form/_matrix_question.html.slim @@ -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" diff --git a/app/views/qae_form/confirm.html.slim b/app/views/qae_form/confirm.html.slim index a482525a4..25f171476 100644 --- a/app/views/qae_form/confirm.html.slim +++ b/app/views/qae_form/confirm.html.slim @@ -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 diff --git a/forms/award_years/v2024/innovation/innovation_step4.rb b/forms/award_years/v2024/innovation/innovation_step4.rb index f639775f9..6ed12ab92 100644 --- a/forms/award_years/v2024/innovation/innovation_step4.rb +++ b/forms/award_years/v2024/innovation/innovation_step4.rb @@ -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 diff --git a/forms/qae_form_builder/by_trade_goods_and_services_label_question.rb b/forms/qae_form_builder/by_trade_goods_and_services_label_question.rb index 3128251a7..ab97504b2 100644 --- a/forms/qae_form_builder/by_trade_goods_and_services_label_question.rb +++ b/forms/qae_form_builder/by_trade_goods_and_services_label_question.rb @@ -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] ||= {} diff --git a/forms/qae_form_builder/by_years_question.rb b/forms/qae_form_builder/by_years_question.rb index 1717ff609..864c97fe5 100644 --- a/forms/qae_form_builder/by_years_question.rb +++ b/forms/qae_form_builder/by_years_question.rb @@ -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 @@ -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 @@ -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 = [] diff --git a/forms/qae_form_builder/one_option_by_years_question.rb b/forms/qae_form_builder/one_option_by_years_question.rb index 0a7787034..7ff8c7bef 100644 --- a/forms/qae_form_builder/one_option_by_years_question.rb +++ b/forms/qae_form_builder/one_option_by_years_question.rb @@ -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 @@ -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