Fix Clear All button using event delegation

- Add clear-all button event handling to container click delegation
- Remove old event listener attachment that failed with dynamic buttons
- Clean up debug logging and warnings
- Clear All button now works correctly after indicators are added
This commit is contained in:
DiTus
2026-02-26 20:25:06 +01:00
parent c3d72b5557
commit 2a791774e7
2 changed files with 26 additions and 19 deletions

View File

@ -357,11 +357,11 @@ function renderIndicatorPresets(indicator, meta) {
function setupEventListeners() { function setupEventListeners() {
const container = document.getElementById('indicatorPanel'); const container = document.getElementById('indicatorPanel');
if (!container) return; if (!container) return;
console.log('[IndicatorPanel] Setting up event listeners...');
// Single event delegation handler for add button
container.addEventListener('click', (e) => { container.addEventListener('click', (e) => {
e.stopPropagation();
// Add button
const addBtn = e.target.closest('.indicator-btn.add'); const addBtn = e.target.closest('.indicator-btn.add');
if (addBtn) { if (addBtn) {
e.stopPropagation(); e.stopPropagation();
@ -372,6 +372,28 @@ function setupEventListeners() {
return; return;
} }
// Remove button
const removeBtn = e.target.closest('.indicator-btn.remove');
if (removeBtn) {
e.stopPropagation();
const id = removeBtn.dataset.id;
if (id && window.removeIndicatorById) {
window.removeIndicatorById(id);
}
return;
}
// Clear all button
const clearAllBtn = e.target.closest('.clear-all');
if (clearAllBtn) {
if (window.clearAllIndicators) {
window.clearAllIndicators();
}
return;
}
return;
}
// Expand/collapse button // Expand/collapse button
const expandBtn = e.target.closest('.indicator-btn.expand'); const expandBtn = e.target.closest('.indicator-btn.expand');
if (expandBtn) { if (expandBtn) {
@ -431,16 +453,6 @@ function setupEventListeners() {
renderIndicatorPanel(); renderIndicatorPanel();
}); });
}); });
// Clear all button
const clearAllBtn = container.querySelector('.clear-all');
if (clearAllBtn) {
clearAllBtn.addEventListener('click', () => {
window.clearAllIndicators();
});
}
console.log('[IndicatorPanel] Event listeners setup complete');
} }
// Actions // Actions
@ -471,8 +483,6 @@ window.updateIndicatorSetting = function(id, key, value) {
}; };
window.clearAllIndicators = function() { window.clearAllIndicators = function() {
console.warn('clearAllIndicators() called - clearing all indicators!');
console.trace('Call stack:');
activeIndicators.forEach(ind => { activeIndicators.forEach(ind => {
ind.series?.forEach(s => { ind.series?.forEach(s => {
try { window.dashboard?.chart?.removeSeries(s); } catch(e) {} try { window.dashboard?.chart?.removeSeries(s); } catch(e) {}

View File

@ -1,8 +1,5 @@
import { getAvailableIndicators, IndicatorRegistry as IR } from '../indicators/index.js'; import { getAvailableIndicators, IndicatorRegistry as IR } from '../indicators/index.js';
console.warn('⚠️ [indicators-panel.js] OLD MODULE DETECTED! This will conflict with indicators-panel-new.js!');
console.trace('[indicators-panel.js] Loading call stack:');
let activeIndicators = []; let activeIndicators = [];
let configuringId = null; let configuringId = null;
let previewingType = null; // type being previewed (not yet added) let previewingType = null; // type being previewed (not yet added)