From 4decf830fb8b436fed0f3fa326a12170c2030565 Mon Sep 17 00:00:00 2001 From: Lubos Hricak Date: Thu, 27 Jul 2023 17:34:33 -0300 Subject: [PATCH 1/3] Fix JS validatons for numeric inputs --- .../frontend/form-validation.js.coffee | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/assets/javascripts/frontend/form-validation.js.coffee b/app/assets/javascripts/frontend/form-validation.js.coffee index 973b5ccb8..215143df0 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) From 98bb98397313f6fe6be53d8f708e0f0248664508 Mon Sep 17 00:00:00 2001 From: Lubos Hricak Date: Thu, 27 Jul 2023 17:37:17 -0300 Subject: [PATCH 2/3] Make innovation 6.X questions required --- app/forms/award_years/v2024/innovation/innovation_step4.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/forms/award_years/v2024/innovation/innovation_step4.rb b/app/forms/award_years/v2024/innovation/innovation_step4.rb index 3245beda7..471430713 100644 --- a/app/forms/award_years/v2024/innovation/innovation_step4.rb +++ b/app/forms/award_years/v2024/innovation/innovation_step4.rb @@ -316,6 +316,7 @@ 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 %(

@@ -334,6 +335,7 @@ 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 type :money label ->(y) { "Financial year #{y}" } @@ -347,6 +349,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 +364,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,6 +387,7 @@ 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 %(

@@ -409,6 +414,7 @@ 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.

From 8bd6efd07169d34768e7bc9d2af4537971be2003 Mon Sep 17 00:00:00 2001 From: Lubos Hricak Date: Thu, 27 Jul 2023 17:38:01 -0300 Subject: [PATCH 3/3] Add more context to innovation 6.X questions --- .../award_years/v2024/innovation/innovation_step4.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/forms/award_years/v2024/innovation/innovation_step4.rb b/app/forms/award_years/v2024/innovation/innovation_step4.rb index 471430713..8d2f93ba5 100644 --- a/app/forms/award_years/v2024/innovation/innovation_step4.rb +++ b/app/forms/award_years/v2024/innovation/innovation_step4.rb @@ -322,7 +322,8 @@ def innovation_step4

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}" } @@ -337,6 +338,7 @@ def innovation_step4 sub_ref "D 6.2" required section :innovation_financials + context %(

Enter '0' if you had none.

) type :money label ->(y) { "Financial year #{y}" } @@ -393,7 +395,8 @@ def innovation_step4

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}" } @@ -418,7 +421,8 @@ def innovation_step4 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"}