mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
added multi_select_controller and added multi-select support for tags without Ctrl/Shift in transaction forms (#55)
* 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
This commit is contained in:
21
app/javascript/controllers/multi_select_controller.js
Normal file
21
app/javascript/controllers/multi_select_controller.js
Normal file
@@ -0,0 +1,21 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,8 @@
|
||||
multiple: true,
|
||||
label: t(".tags_label"),
|
||||
container_class: "h-40"
|
||||
} %>
|
||||
},
|
||||
{ "data-controller": "multi-select" } %>
|
||||
<% end %>
|
||||
<%= f.text_area :notes,
|
||||
label: t(".note_label"),
|
||||
|
||||
@@ -84,7 +84,8 @@
|
||||
label: t(".tags_label"),
|
||||
container_class: "h-40"
|
||||
},
|
||||
{ "data-auto-submit-form-target": "auto" } %>
|
||||
{ "data-controller": "multi-select", "data-auto-submit-form-target": "auto" }
|
||||
%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user