diff --git a/app/helpers/numeric_questions_helper.rb b/app/helpers/numeric_questions_helper.rb index 464f42723..c0fe05ce3 100644 --- a/app/helpers/numeric_questions_helper.rb +++ b/app/helpers/numeric_questions_helper.rb @@ -5,7 +5,7 @@ module NumericQuestionsHelper { "data-controller": "numeric-question", "data-action": "numeric-question#calculateFields", - "data-target": "#{question['result-field'].to_s.dasherize}-field", + "data-target": "case-log-#{question['result-field'].to_s.dasherize}-field", "data-calculated": question["fields-to-add"].to_json, } end diff --git a/app/javascript/controllers/numeric_question_controller.js b/app/javascript/controllers/numeric_question_controller.js index 6a0a58d78..355e1686b 100644 --- a/app/javascript/controllers/numeric_question_controller.js +++ b/app/javascript/controllers/numeric_question_controller.js @@ -3,7 +3,7 @@ import { Controller } from "@hotwired/stimulus" export default class extends Controller { calculateFields() { const affectedField = this.element.dataset.target; - const fieldsToAdd = JSON.parse(this.element.dataset.calculated).map(x => `${x.replaceAll("_","-")}-field`); + const fieldsToAdd = JSON.parse(this.element.dataset.calculated).map(x => `case-log-${x.replaceAll("_","-")}-field`); const valuesToAdd = fieldsToAdd.map(x => document.getElementById(x).value).filter(x => x); const newValue = valuesToAdd.map(x => parseInt(x)).reduce((a, b) => a + b, 0); const elementToUpdate = document.getElementById(affectedField); diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 3f2b8039f..b86320615 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -118,17 +118,17 @@ RSpec.describe "Test Features" do it "updates total value of the rent", js: true do visit("/case_logs/#{id}/rent") - fill_in("basic_rent", with: 3) - expect(page).to have_field("total-charge-field", with: "3") + fill_in("case-log-basic-rent-field", with: 3) + expect(page).to have_field("case-log-total-charge-field", with: "3") - fill_in("service_charge", with: 2) - expect(page).to have_field("total-charge-field", with: "5") + fill_in("case-log-service-charge-field", with: 2) + expect(page).to have_field("case-log-total-charge-field", with: "5") - fill_in("personal_service_charge", with: 1) - expect(page).to have_field("total-charge-field", with: "6") + fill_in("case-log-personal-service-charge-field", with: 1) + expect(page).to have_field("case-log-total-charge-field", with: "6") - fill_in("support_charge", with: 4) - expect(page).to have_field("total-charge-field", with: "10") + fill_in("case-log-support-charge-field", with: 4) + expect(page).to have_field("case-log-total-charge-field", with: "10") end end diff --git a/spec/helpers/numeric_questions_helper_spec.rb b/spec/helpers/numeric_questions_helper_spec.rb index 48877babe..5302d9eaa 100644 --- a/spec/helpers/numeric_questions_helper_spec.rb +++ b/spec/helpers/numeric_questions_helper_spec.rb @@ -13,7 +13,7 @@ RSpec.describe NumericQuestionsHelper do expect(numeric_question_html_attributes(questions["basic_rent"])).to eq({ "data-controller": "numeric-question", "data-action": "numeric-question#calculateFields", - "data-target": "#{questions['basic_rent']['result-field'].to_s.dasherize}-field", + "data-target": "case-log-#{questions['basic_rent']['result-field'].to_s.dasherize}-field", "data-calculated": questions["basic_rent"]["fields-to-add"].to_json, }) end