@@ -2555,11 +2555,25 @@ const SettingsForms = {
2555
2555
}
2556
2556
2557
2557
let hasChanges = false ;
2558
+ let suppressInitialDetection = true ; // Suppress change detection during initial setup
2558
2559
2559
2560
// Clear any existing unsaved changes state and warnings when setting up
2560
2561
window . notificationsUnsavedChanges = false ;
2561
2562
this . removeUnsavedChangesWarning ( ) ;
2562
2563
2564
+ // Ensure originalSettings has the same defaults used in form generation
2565
+ // This prevents mismatches between form display values and change detection
2566
+ const normalizedSettings = {
2567
+ enable_notifications : originalSettings . enable_notifications !== undefined ? originalSettings . enable_notifications : false ,
2568
+ notification_level : originalSettings . notification_level || 'warning' ,
2569
+ apprise_urls : originalSettings . apprise_urls || [ ] ,
2570
+ notify_on_missing : originalSettings . notify_on_missing !== undefined ? originalSettings . notify_on_missing : true ,
2571
+ notify_on_upgrade : originalSettings . notify_on_upgrade !== undefined ? originalSettings . notify_on_upgrade : true ,
2572
+ notification_include_instance : originalSettings . notification_include_instance !== undefined ? originalSettings . notification_include_instance : true ,
2573
+ notification_include_app : originalSettings . notification_include_app !== undefined ? originalSettings . notification_include_app : true ,
2574
+ ...originalSettings // Keep any other settings that might exist
2575
+ } ;
2576
+
2563
2577
// Initialize button in disabled/grey state immediately
2564
2578
saveButton . disabled = true ;
2565
2579
saveButton . style . background = '#6b7280' ;
@@ -2601,6 +2615,12 @@ const SettingsForms = {
2601
2615
2602
2616
// Function to detect changes in form elements
2603
2617
const detectChanges = ( ) => {
2618
+ // Skip change detection if still in initial setup phase
2619
+ if ( suppressInitialDetection ) {
2620
+ console . log ( '[SettingsForms] Notifications change detection suppressed during initial setup' ) ;
2621
+ return ;
2622
+ }
2623
+
2604
2624
// Check regular form inputs
2605
2625
const inputs = container . querySelectorAll ( 'input, select, textarea' ) ;
2606
2626
let formChanged = false ;
@@ -2615,15 +2635,15 @@ const SettingsForms = {
2615
2635
let originalValue , currentValue ;
2616
2636
2617
2637
if ( input . type === 'checkbox' ) {
2618
- originalValue = originalSettings [ key ] !== undefined ? originalSettings [ key ] : false ;
2638
+ originalValue = normalizedSettings [ key ] !== undefined ? normalizedSettings [ key ] : false ;
2619
2639
currentValue = input . checked ;
2620
2640
} else if ( input . type === 'number' ) {
2621
2641
// Get default from input attributes or use 0
2622
2642
const defaultValue = parseInt ( input . getAttribute ( 'value' ) ) || parseInt ( input . min ) || 0 ;
2623
- originalValue = originalSettings [ key ] !== undefined ? parseInt ( originalSettings [ key ] ) : defaultValue ;
2643
+ originalValue = normalizedSettings [ key ] !== undefined ? parseInt ( normalizedSettings [ key ] ) : defaultValue ;
2624
2644
currentValue = parseInt ( input . value ) || 0 ;
2625
2645
} else {
2626
- originalValue = originalSettings [ key ] || '' ;
2646
+ originalValue = normalizedSettings [ key ] || '' ;
2627
2647
currentValue = input . value . trim ( ) ;
2628
2648
}
2629
2649
@@ -2638,7 +2658,7 @@ const SettingsForms = {
2638
2658
// Special handling for apprise_urls which is a textarea with newlines
2639
2659
const appriseUrlsElement = container . querySelector ( '#apprise_urls' ) ;
2640
2660
if ( appriseUrlsElement ) {
2641
- const originalUrls = originalSettings . apprise_urls || [ ] ;
2661
+ const originalUrls = normalizedSettings . apprise_urls || [ ] ;
2642
2662
const currentUrls = appriseUrlsElement . value . split ( '\n' )
2643
2663
. map ( url => url . trim ( ) )
2644
2664
. filter ( url => url . length > 0 ) ;
@@ -2684,7 +2704,7 @@ const SettingsForms = {
2684
2704
// Update original settings for future change detection
2685
2705
const updatedSettings = window . huntarrUI . getFormSettings ( 'general' ) ;
2686
2706
if ( updatedSettings ) {
2687
- Object . assign ( originalSettings , updatedSettings ) ;
2707
+ Object . assign ( normalizedSettings , updatedSettings ) ;
2688
2708
}
2689
2709
2690
2710
} ) . catch ( error => {
@@ -2700,9 +2720,24 @@ const SettingsForms = {
2700
2720
// Initial change detection - ensure form is fully loaded before checking
2701
2721
// Use a longer timeout to ensure all form elements are properly initialized
2702
2722
setTimeout ( ( ) => {
2703
- console . log ( '[SettingsForms] Running initial change detection for Notifications' ) ;
2723
+ console . log ( '[SettingsForms] Initializing notifications form baseline' ) ;
2724
+
2725
+ // Force button to grey state and clear any changes
2726
+ saveButton . disabled = true ;
2727
+ saveButton . style . background = '#6b7280' ;
2728
+ saveButton . style . color = '#9ca3af' ;
2729
+ saveButton . style . borderColor = '#4b5563' ;
2730
+ saveButton . style . cursor = 'not-allowed' ;
2731
+ window . notificationsUnsavedChanges = false ;
2732
+ hasChanges = false ;
2733
+
2734
+ // Enable change detection now that form is properly initialized
2735
+ suppressInitialDetection = false ;
2736
+ console . log ( '[SettingsForms] Notifications change detection enabled - button should remain grey unless changes made' ) ;
2737
+
2738
+ // Run one final change detection to confirm no changes detected
2704
2739
detectChanges ( ) ;
2705
- } , 200 ) ;
2740
+ } , 500 ) ;
2706
2741
} ,
2707
2742
2708
2743
// Set up manual save functionality for Swaparr
0 commit comments