From edecba859900638646a2ac6d1ce47230c3323de3 Mon Sep 17 00:00:00 2001 From: David Gay Date: Sat, 5 Jun 2021 21:25:36 -0400 Subject: Display costs and requirements for selected activity in select fields via Stimulus + fetch --- .../controllers/activity_select_controller.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/javascript/controllers/activity_select_controller.js (limited to 'app/javascript') diff --git a/app/javascript/controllers/activity_select_controller.js b/app/javascript/controllers/activity_select_controller.js new file mode 100644 index 0000000..2acfcdd --- /dev/null +++ b/app/javascript/controllers/activity_select_controller.js @@ -0,0 +1,17 @@ +import { Controller } from "stimulus"; + +export default class extends Controller { + static targets = [ "select", "output" ]; + + connect() { + this.load(); + } + + load() { + fetch(`/activities/${this.selectTarget.value}/costs_and_requirements`) + .then(response => response.text()) + .then(html => { + this.outputTarget.innerHTML = html; + }); + } +} -- cgit v1.2.3