Browse Source

Make sure we only run the stimulus init once per page load

pull/77/head
baarkerlounger 4 years ago
parent
commit
5f2c1e4c13
  1. 5
      app/javascript/controllers/soft_validations_controller.js
  2. 2
      app/views/form/_validation_override_question.html.erb
  3. 1
      spec/features/case_log_spec.rb

5
app/javascript/controllers/soft_validations_controller.js

@ -1,7 +1,10 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static values = { run: Number }
initialize() {
if(this.runValue == 0){
let url = window.location.href + "/soft_validations"
let xhr = new XMLHttpRequest()
let div = document.getElementById("soft-validations")
@ -26,5 +29,7 @@ export default class extends Controller {
}
}
xhr.send()
this.runValue++
}
}
}

2
app/views/form/_validation_override_question.html.erb

@ -2,7 +2,7 @@
<%= f.govuk_check_boxes_fieldset page_info["soft_validations"]&.keys&.first,
legend: { text: "soft-validations-placeholder-message", size: "l" },
hint: { text: "soft-validations-placeholder-hint-text" },
form_group: { "data-controller": "soft-validations" } do %>
form_group: { "data-controller": "soft-validations", "data-run": "0" } do %>
<%= f.govuk_check_box page_info["soft_validations"]&.keys&.first, page_info["soft_validations"]&.keys&.first,
label: { text: "Yes" }

1
spec/features/case_log_spec.rb

@ -405,7 +405,6 @@ RSpec.describe "Test Features" do
choose("case-log-net-income-frequency-weekly-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_content("Are you sure this is correct?")
binding.pry
check("case-log-override-net-income-validation-override-net-income-validation-field", allow_label_click: true)
click_button("Save and continue")
expect(page).to have_current_path("/case_logs/#{case_log.id}/net_income_uc_proportion")

Loading…
Cancel
Save