UNPKG

@excelwebzone/symfony-admin-ui

Version:

Symfony Admin UI is a simple set of UI behaviors and components used with your [symfony-admin](https://github.com/excelwebzone/symfony-admin-bundle) application.

29 lines (22 loc) 593 B
import $ from 'jquery'; export default class SwitchButton { constructor(containerEl) { this.$container = $(containerEl); this.bindEvents(); } bindEvents() { this.$container.on('click', '.switch', (e) => this.toggle(e)); } toggle(e) { const $checkbox = $(e.currentTarget).parent(); $checkbox.toggleClass('checked'); $checkbox .parent('.checkbox') .next('.switch-button-text') .toggleClass(' is-active'); $checkbox .find('input[type="hidden"]') .val($checkbox.hasClass('checked') ? 1 : 0) .trigger('change'); } }