clicking a PkCheckbox updates state

This commit is contained in:
CroogQT 2022-05-05 12:37:28 -07:00
parent c536944a10
commit db142061ff
4 changed files with 21 additions and 5 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,21 @@
import { getElement, getElements, findFirstAdjacent } from '../util'; import { getElements } from '../util';
import { StateManager } from 'src/state';
import { previousPkCheckState } from '../stores';
export function initSelectMultiple(): void { type PreviousPkCheckState = { element: Nullable<HTMLInputElement> };
function updatePreviousPkCheckState(eventTargetElement: HTMLInputElement, state: StateManager<PreviousPkCheckState>): void {
console.log(state)
state.set('element', eventTargetElement);
} }
export function initSelectMultiple(): void {
const checkboxElements = getElements<HTMLInputElement>('input[type="checkbox"][name="pk"]');
for (const element of checkboxElements) {
element.addEventListener('click', (event) => {
event.stopPropagation();
updatePreviousPkCheckState(event.target as HTMLInputElement, previousPkCheckState);
});
}
}

View File

@ -1,7 +1,7 @@
import { createState } from '../state'; import { createState } from '../state';
export const previousPKCheckState = createState<{ hidden: boolean }>( export const previousPkCheckState = createState<{ element: Nullable<HTMLInputElement> }>(
{ hidden: false }, { element: null},
{ persist: false }, { persist: false }
); );