diff --git a/app/helpers/conditional_questions_helper.rb b/app/helpers/conditional_questions_helper.rb index ec9ccae60..5a1aa394d 100644 --- a/app/helpers/conditional_questions_helper.rb +++ b/app/helpers/conditional_questions_helper.rb @@ -4,6 +4,6 @@ module ConditionalQuestionsHelper end def display_question_key_div(page, question) - "style='display:none;'".html_safe if conditional_questions_for_page(page).include?(question.id) + "style='display:none;'".html_safe if conditional_questions_for_page(page).include?(question.id) || question.requires_js end end diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 6bf5039ca..2bf2d4345 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -3,7 +3,7 @@ class Form::Question :type, :min, :max, :step, :width, :fields_to_add, :result_field, :conditional_for, :readonly, :answer_options, :page, :check_answer_label, :inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value, - :guidance_partial, :prefix, :suffix + :guidance_partial, :prefix, :suffix, :requires_js def initialize(id, hsh, page) @id = id @@ -26,6 +26,7 @@ class Form::Question @hidden_in_check_answers = hsh["hidden_in_check_answers"] @prefix = hsh["prefix"] @suffix = hsh["suffix"] + @requires_js = hsh["requires_js"] @page = page end diff --git a/app/webpacker/controllers/numeric_question_controller.js b/app/webpacker/controllers/numeric_question_controller.js index 355e1686b..9bbdf6f9e 100644 --- a/app/webpacker/controllers/numeric_question_controller.js +++ b/app/webpacker/controllers/numeric_question_controller.js @@ -1,6 +1,13 @@ import { Controller } from "@hotwired/stimulus" export default class extends Controller { + connect() { + const affectedField = this.element.dataset.target; + const targetQuestion = affectedField.split("case-log-")[1].split("-field")[0] + const div = document.getElementById(targetQuestion + "_div"); + div.style.display = "block"; + } + calculateFields() { const affectedField = this.element.dataset.target; const fieldsToAdd = JSON.parse(this.element.dataset.calculated).map(x => `case-log-${x.replaceAll("_","-")}-field`); diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index da5a0bb0e..5057626e8 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -2018,7 +2018,8 @@ "type": "numeric", "min": 0, "step": 1, - "readonly": true + "readonly": true, + "requires_js": true }, "hbrentshortfall": { "check_answer_label": "After housing benefit and/or housing element of UC payment is received, will there be an outstanding amount for basic rent and/or benefit eligible charges?",