diff --git a/app/assets/javascripts/frontend/form-validation.js.coffee b/app/assets/javascripts/frontend/form-validation.js.coffee index 973b5ccb8b..215143df0d 100644 --- a/app/assets/javascripts/frontend/form-validation.js.coffee +++ b/app/assets/javascripts/frontend/form-validation.js.coffee @@ -389,6 +389,30 @@ window.FormValidation = if errors @addErrorClass(question) + validateNumberByYears: (question) -> + inputCellsCounter = 0 + + for subquestion in question.find("input") + subq = $(subquestion) + qParent = subq.closest(".js-fy-entries") + errContainer = subq.closest(".span-financial") + + shownQuestion = true + for conditional in $(subquestion).parents('.js-conditional-question') + if !$(conditional).hasClass('show-question') + shownQuestion = false + + if shownQuestion + inputCellsCounter += 1 + + if not subq.val() and question.hasClass("question-required") + @logThis(question, "validateNumberByYears", "This field is required") + @appendMessage(errContainer, "This field is required") + @addErrorClass(question) + continue + else if not subq.val() + continue + validateMoneyByYears: (question) -> inputCellsCounter = 0 @@ -660,6 +684,10 @@ window.FormValidation = if question.hasClass("question-matrix") @validateMatrix(question, triggeringElement) + if question.hasClass("question-number-by-years") + # console.log "validateNumberByYears" + @validateNumberByYears(question) + if question.hasClass("question-money-by-years") # console.log "validateMoneyByYears" @validateMoneyByYears(question) diff --git a/app/forms/award_years/v2024/innovation/innovation_step4.rb b/app/forms/award_years/v2024/innovation/innovation_step4.rb index 3245beda7e..8d2f93ba5e 100644 --- a/app/forms/award_years/v2024/innovation/innovation_step4.rb +++ b/app/forms/award_years/v2024/innovation/innovation_step4.rb @@ -316,12 +316,14 @@ def innovation_step4 by_years :units_sold, "Number of innovative units or contracts sold (if applicable)." do classes "sub-question" sub_ref "D 6.1" + required section :innovation_financials context %(

We recommend that you answer question C2.2 before proceeding with this and further questions, as this will automatically adjust the number of years you need to provide the figures for.

- ) +

Enter '0' if you had none.

+ ).squish type :number label ->(y) { "Financial year #{y}" } @@ -334,7 +336,9 @@ def innovation_step4 by_years :sales, "Sales of your innovative product/service (if applicable)." do classes "sub-question" sub_ref "D 6.2" + required section :innovation_financials + context %(

Enter '0' if you had none.

) type :money label ->(y) { "Financial year #{y}" } @@ -347,6 +351,7 @@ def innovation_step4 by_years :sales_exports, "Of which exports (if applicable)." do classes "sub-question" sub_ref "D 6.3" + required section :innovation_financials context %(

Enter '0' if you had none.

) type :money @@ -361,6 +366,7 @@ def innovation_step4 by_years :sales_royalties, "Of which royalties or licences (if applicable)." do classes "sub-question" sub_ref "D 6.4" + required section :innovation_financials context %(

Enter '0' if you had none.

) type :money @@ -383,12 +389,14 @@ def innovation_step4 by_years :avg_unit_price, "Average unit selling price or contract value (if applicable)." do classes "sub-question" sub_ref "D 6.6" + required section :innovation_financials context %(

If your innovation is a product, you must provide the unit price.

- ) +

Enter '0' if you had none.

+ ).squish type :money label ->(y) { "Financial year #{y}" } @@ -409,10 +417,12 @@ def innovation_step4 by_years :avg_unit_cost_self, "Direct cost, to you, of a single unit or contract (if applicable)." do classes "sub-question" sub_ref "D 6.8" + required section :innovation_financials context %(

If you haven't reached your latest year-end, use estimates to complete this question.

- ) +

Enter '0' if you had none.

+ ).squish type :money label ->(y) { "Financial year #{y}" } by_year_condition :innovation_was_launched_in_the_market, ->(v) { Utils::Date.within_range?(v, AwardYear.start_trading_between(2, 3)) }, 2, data: {value: AwardYear.start_trading_between(2, 3, minmax: true, format: true), type: :range, identifier: "2 to 3"}