import { Controller } from '@hotwired/stimulus'; export default class extends Controller { static targets = ['container']; connect() { if (this.hasContainerTarget && window.turnstile) { console.log('Connecting Turnstile Handleable Controller'); this.widgetId = turnstile.render(this.containerTarget, { callback: () => { this.enableSubmit(); }, }); } } disconnect() { if (this.hasContainerTarget && window.turnstile) { turnstile.remove(this.widgetId); this.widgetId = null; } } enableSubmit() { this.element.querySelectorAll('input[type=submit], button[type=submit]').forEach((el) => { el.disabled = false; }); } disableSubmit() { this.element.querySelectorAll('input[type=submit], button[type=submit]').forEach((el) => { el.disabled = true; }); } }