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:
@ -357,11 +357,11 @@ function renderIndicatorPresets(indicator, meta) {
|
||||
function setupEventListeners() {
|
||||
const container = document.getElementById('indicatorPanel');
|
||||
if (!container) return;
|
||||
|
||||
console.log('[IndicatorPanel] Setting up event listeners...');
|
||||
|
||||
// Single event delegation handler for add button
|
||||
|
||||
container.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
|
||||
// Add button
|
||||
const addBtn = e.target.closest('.indicator-btn.add');
|
||||
if (addBtn) {
|
||||
e.stopPropagation();
|
||||
@ -372,6 +372,28 @@ function setupEventListeners() {
|
||||
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
|
||||
const expandBtn = e.target.closest('.indicator-btn.expand');
|
||||
if (expandBtn) {
|
||||
@ -431,16 +453,6 @@ function setupEventListeners() {
|
||||
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
|
||||
@ -471,8 +483,6 @@ window.updateIndicatorSetting = function(id, key, value) {
|
||||
};
|
||||
|
||||
window.clearAllIndicators = function() {
|
||||
console.warn('clearAllIndicators() called - clearing all indicators!');
|
||||
console.trace('Call stack:');
|
||||
activeIndicators.forEach(ind => {
|
||||
ind.series?.forEach(s => {
|
||||
try { window.dashboard?.chart?.removeSeries(s); } catch(e) {}
|
||||
|
||||
Reference in New Issue
Block a user