1- import { ChangeEvent } from 'react' ;
21import { BaseInputsList } from '../../partials' ;
32
43export enum CheckboxesListFieldAction {
@@ -9,6 +8,11 @@ export enum CheckboxesListFieldAction {
98export class CheckboxesListField extends BaseInputsList < string [ ] > {
109 private _itemsContainer : HTMLDivElement ;
1110
11+ static EVENTS = {
12+ ...BaseInputsList . EVENTS ,
13+ CHANGE : 'ids:checkboxes-list-field:change' ,
14+ } ;
15+
1216 constructor ( container : HTMLDivElement ) {
1317 super ( container ) ;
1418
@@ -21,11 +25,12 @@ export class CheckboxesListField extends BaseInputsList<string[]> {
2125 this . _itemsContainer = itemsContainer ;
2226
2327 this . onItemChange = this . onItemChange . bind ( this ) ;
24- // this.onChange = this.onChange.bind(this);
2528 }
2629
2730 getItemsCheckboxes ( ) {
28- const itemsCheckboxes = [ ...this . _itemsContainer . querySelectorAll < HTMLInputElement > ( '.ids-choice-input-field .ids-input--checkbox' ) ] ;
31+ const itemsCheckboxes = [
32+ ...this . _itemsContainer . querySelectorAll < HTMLInputElement > ( '.ids-choice-input-field .ids-input--checkbox' ) ,
33+ ] ;
2934
3035 return itemsCheckboxes ;
3136 }
@@ -56,19 +61,15 @@ export class CheckboxesListField extends BaseInputsList<string[]> {
5661 }
5762
5863 onChange ( nextValue : string [ ] , itemValue : string , actionPerformed : CheckboxesListFieldAction ) {
59- const changeEvent = new CustomEvent ( 'change' , {
64+ const changeEvent = new CustomEvent ( CheckboxesListField . EVENTS . CHANGE , {
6065 bubbles : true ,
61- detail : [
62- nextValue ,
63- itemValue ,
64- actionPerformed ,
65- ] ,
66+ detail : [ nextValue , itemValue , actionPerformed ] ,
6667 } ) ;
6768
69+ console . log ( changeEvent . detail ) ;
6870 this . _container . dispatchEvent ( changeEvent ) ;
6971 }
7072
71-
7273 initCheckboxes ( ) {
7374 const itemsCheckboxes = this . getItemsCheckboxes ( ) ;
7475
@@ -77,6 +78,21 @@ export class CheckboxesListField extends BaseInputsList<string[]> {
7778 } ) ;
7879 }
7980
81+ unbindCheckboxes ( ) {
82+ const itemsCheckboxes = this . getItemsCheckboxes ( ) ;
83+
84+ itemsCheckboxes . forEach ( ( checkbox ) => {
85+ checkbox . removeEventListener ( 'change' , this . onItemChange , false ) ;
86+ } ) ;
87+ }
88+
89+ reinit ( ) {
90+ super . reinit ( ) ;
91+
92+ this . unbindCheckboxes ( ) ;
93+ this . initCheckboxes ( ) ;
94+ }
95+
8096 init ( ) {
8197 super . init ( ) ;
8298
0 commit comments