mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 06:21:23 +00:00
* added multi_select_controller and added multi-select support for tags without Ctrl/Shift in transaction forms * fix: prevent memory leak by properly cleaning up event listener in multi-select controller * chore: updated indentation
21 lines
544 B
JavaScript
21 lines
544 B
JavaScript
import { Controller } from "@hotwired/stimulus";
|
|
|
|
export default class extends Controller {
|
|
connect() {
|
|
this.element.addEventListener('mousedown', this.toggleOption);
|
|
}
|
|
|
|
disconnect() {
|
|
this.element.removeEventListener('mousedown', this.toggleOption);
|
|
}
|
|
|
|
toggleOption = (e) => {
|
|
const option = e.target;
|
|
if (option.tagName === 'OPTION') {
|
|
e.preventDefault();
|
|
option.selected = !option.selected;
|
|
const event = new Event('change', { bubbles: true });
|
|
this.element.dispatchEvent(event);
|
|
}
|
|
}
|
|
} |