Ticket board: delegated actions and filtering
Project milestone
Keep filtering as a derived view and route state changes through one delegated click listener. Closing a ticket changes the model before regenerating the visible list.
Run the examples
Open projects/ticket-board/index.html fresh for each example and run the JavaScript in its browser console.
document.querySelector('#title').value = 'Printer';document.querySelector('#create').requestSubmit();document.querySelector('#tickets button').click();console.log(document.querySelector('#tickets button').textContent);Expected console output:
ReopenClosing the ticket makes reopening the next available action.
Open projects/ticket-board/index.html fresh for each example and run the JavaScript in its browser console.
document.querySelector('#title').value = 'Printer';document.querySelector('#create').requestSubmit();filter.value = 'open'; filter.dispatchEvent(new Event('change'));document.querySelector('#tickets button').click();console.log(document.querySelector('#status').textContent);console.log(document.activeElement.id);Expected console output:
0 of 1 ticketsfilterThe record remains stored but disappears from the filtered view; focus moves to the filter.
Implementation and contract
visibleTickets() selects all, open or closed records. The list listener finds the nearest button with a data-id and confirms it belongs to the list. It converts the ID to a number and replaces only the matching record. render(id) then recreates the list and restores focus to the matching action, or the filter if that record disappears.
Common mistakes
Do not delete closed tickets merely because they disappear from the open view. Do not leave focus on a removed element.
Acceptance task
Add a closed-only filter case to the browser test suite; verify that switching back to All restores every record.
Project source, setup and tests: projects/ticket-board/README.md. Read the implementation before modifying it; the tests check the supplied baseline, not every possible implementation.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Ticket board: delegated actions and filtering — Knowledge Check
Assess implementation decisions and project behavior.
What should a filter change modify?
Why check list.contains(button)?
Where should focus move if the acted-on row is filtered out?
In the Ticket board: delegated actions and filtering lab, what does this independent example log? document.querySelector('#title').value = 'Printer'; document.querySelector('#create').requestSubmit(); document.querySelector('#tickets button').click(); console.log(document.querySelector('#tickets button').textContent);
In the Ticket board: delegated actions and filtering lab, what does this independent example log? document.querySelector('#title').value = 'Printer'; document.querySelector('#create').requestSubmit(); filter.value = 'open'; filter.dispatchEvent(new Event('change')); document.querySelector('#tickets button').click(); console.log(document.querySelector('#status').textContent); console.log(document.activeElement.id);