-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsubject_selector_controller.js
More file actions
45 lines (41 loc) · 1.17 KB
/
subject_selector_controller.js
File metadata and controls
45 lines (41 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Controller } from "@hotwired/stimulus";
import Choices from "choices.js";
export default class extends Controller {
static targets = ["select", "submitButton"];
connect() {
this.choices = new Choices(this.selectTarget, {
searchEnabled: true,
searchPlaceholderValue: "Buscar materia...",
placeholderValue: "Seleccionar materia...",
itemSelectText: "",
noResultsText: "No se encontraron materias",
noChoicesText: "No hay materias disponibles",
shouldSort: false,
classNames: {
containerOuter: ["choices", "!m-0", "!h-10", "flex-grow-1"],
containerInner: [
"choices__inner",
"!min-h-10",
"!h-10",
"!flex",
"!items-center",
"!bg-white",
"!rounded-md",
"!px-4",
"!py-3",
"!border-none",
],
listSingle: ["choices__list", "choices__list--single", "!p-0"],
},
});
}
onChange() {
const selectedValue = this.selectTarget.value;
this.submitButtonTarget.disabled = !selectedValue || selectedValue === "";
}
disconnect() {
if (this.choices) {
this.choices.destroy();
}
}
}