document.addEventListener('alpine:init', () => { Alpine.data('switchToggle', (initial) => ({ on: initial, toggle() { this.on = !this.on; this.$el.classList.toggle('active', this.on); this.$nextTick(() => { const hidden = this.$el.nextElementSibling; if (hidden) hidden.value = this.on ? 'on' : ''; }); } })); });