Skip to content

Commit

Permalink
Merge pull request #2442 from bitzesty/additional-question-validation…
Browse files Browse the repository at this point in the history
…s-staging

Additional question validations [staging]
  • Loading branch information
Lubosky authored Aug 1, 2023
2 parents dac1df9 + 8bd6efd commit a252017
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
28 changes: 28 additions & 0 deletions app/assets/javascripts/frontend/form-validation.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
16 changes: 13 additions & 3 deletions app/forms/award_years/v2024/innovation/innovation_step4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %(
<p>
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.
</p>
)
<p>Enter '0' if you had none.</p>
).squish
type :number
label ->(y) { "Financial year #{y}" }

Expand All @@ -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 %(<p>Enter '0' if you had none.</p>)
type :money
label ->(y) { "Financial year #{y}" }

Expand All @@ -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 %(<p>Enter '0' if you had none.</p>)
type :money
Expand All @@ -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 %(<p>Enter '0' if you had none.</p>)
type :money
Expand All @@ -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 %(
<p>
If your innovation is a product, you must provide the unit price.
</p>
)
<p>Enter '0' if you had none.</p>
).squish

type :money
label ->(y) { "Financial year #{y}" }
Expand All @@ -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 %(
<p>If you haven't reached your latest year-end, use estimates to complete this question.</p>
)
<p>Enter '0' if you had none.</p>
).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"}
Expand Down

0 comments on commit a252017

Please sign in to comment.