(e)
| 2666 | if (!element) return; |
| 2667 | |
| 2668 | const handler = async (e) => { |
| 2669 | // Verify that we still have a valid model selected before saving |
| 2670 | // Check both the path tree container and the current model details path |
| 2671 | const pathTreeContainer = document.getElementById('path-tree-container'); |
| 2672 | const pathFromContainer = pathTreeContainer?.getAttribute('data-file-path') || ''; |
| 2673 | const currentPath = pathFromContainer || getCurrentModelFilePath() || currentModelDetailsPath; |
| 2674 | |
| 2675 | // If no path exists or it doesn't match the original filePath, don't save |
| 2676 | if (!currentPath || currentPath !== filePath || !pathFromContainer) { |
| 2677 | console.log('No valid model selected, ignoring checkbox change'); |
| 2678 | // Revert the checkbox to its previous state |
| 2679 | if (config.type === 'checkbox') { |
| 2680 | e.target.checked = !e.target.checked; |
| 2681 | } |
| 2682 | return; |
| 2683 | } |
| 2684 | |
| 2685 | const value = config.type === 'checkbox' ? e.target.checked : e.target.value; |
| 2686 | await autoSaveModel(config.field, value, filePath); |
| 2687 | }; |
| 2688 | |
| 2689 | if (config.useChange) { |
| 2690 | element.addEventListener('change', handler); |
no test coverage detected