Skip to content

Commit

Permalink
Create primary details stimulus controller
Browse files Browse the repository at this point in the history
  • Loading branch information
binarygit committed Aug 9, 2022
1 parent 2d53941 commit 09b2130
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/webpacker/controllers/primary_details_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Controller } from "stimulus"
import CableReady from "cable_ready"

export default class extends Controller {
static values = { primaryProducer: String, enterpriseSells: String }

primaryProducerChanged(event) {
this.primaryProducerValue = event.currentTarget.checked
this.makeRequest()
}

enterpriseSellsChanged(event) {
if (event.currentTarget.checked) {
this.enterpriseSellsValue = event.currentTarget.value
this.makeRequest()
}
}

makeRequest() {
fetch(`?stimulus=true&enterprise_sells=${this.enterpriseSellsValue}&is_primary_producer=${this.primaryProducerValue}`, {
method: "GET",
headers: { "Content-type": "application/json; charset=UTF-8" }
}).then(data => data.json()).then(CableReady.perform)
}
}

0 comments on commit 09b2130

Please sign in to comment.