PageSourceSearch

https://powercoach.ai/assets/controllers/stat_checkbox_controller-11a7fde9.js

js powercoach.ai collected 2026-10-05 14:00:49 UTC 1,482 bytes, 53 lines download raw bytes

1import { Controller } from "@hotwired/stimulus"
2
3// Connects to data-controller="stat-checkbox"
4// Handles stat checkbox selection with count validation (min 4, max 8).
5// Used on admin/sports/default_stats and games/customize_stats pages.
6export default class extends Controller {
7  static targets = ["checkbox", "count", "submitButton", "alert"]
8
9  static values = {
10    min: { type: Number, default: 4 },
11    max: { type: Number, default: 8 }
12  }
13
14  connect() {
15    this.updateCount()
16    this.updateSelectionVisuals()
17  }
18
19  toggle() {
20    this.updateCount()
21    this.updateSelectionVisuals()
22  }
23
24  updateCount() {
25    const checkedCount = this.checkboxTargets.filter(cb => cb.checked).length
26
27    if (this.hasCountTarget) {
28      this.countTarget.textContent = checkedCount
29    }
30
31    if (this.hasAlertTarget) {
32      const isValid = checkedCount >= this.minValue && checkedCount <= this.maxValue
33      this.alertTarget.className = `alert ${isValid ? "alert-success" : "alert-info"}`
34    }
35
36    if (this.hasSubmitButtonTarget) {
37      this.submitButtonTarget.disabled = checkedCount < this.minValue || checkedCount > this.maxValue
38    }
39  }
40
41  updateSelectionVisuals() {
42    this.checkboxTargets.forEach(checkbox => {
43      const wrapper = checkbox.closest(".stat-selection-wrapper")
44      if (wrapper) {
45        if (checkbox.checked) {
46          wrapper.classList.add("selected")
47        } else {
48          wrapper.classList.remove("selected")
49        }
50      }
51    })
52  }
53}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.