@@ -11,6 +11,9 @@ function initializeApp() {
1111 // Initialize form validation
1212 initializeFormValidation ( ) ;
1313
14+ // Initialize silent password matching
15+ initializeSilentPasswordMatching ( ) ;
16+
1417 // Initialize offline functionality
1518 initializeOfflineSupport ( ) ;
1619
@@ -27,6 +30,40 @@ function initializeApp() {
2730 saveCurrentPage ( ) ;
2831}
2932
33+ function initializeSilentPasswordMatching ( ) {
34+ const newPassword = document . getElementById ( 'new_password' ) ;
35+ const confirmPassword = document . getElementById ( 'confirm_password' ) ;
36+ const statusDiv = document . getElementById ( 'passwordMatchStatus' ) ;
37+
38+ if ( ! newPassword || ! confirmPassword || ! statusDiv ) return ;
39+
40+ function updateStatus ( ) {
41+ const val1 = newPassword . value ;
42+ const val2 = confirmPassword . value ;
43+
44+ if ( ! val1 && ! val2 ) {
45+ statusDiv . style . display = 'none' ;
46+ return ;
47+ }
48+
49+ statusDiv . style . display = 'block' ;
50+ if ( val1 === val2 && val1 !== '' ) {
51+ statusDiv . textContent = '✓ Passwords match' ;
52+ statusDiv . className = 'small mt-2 text-center py-1 rounded bg-success-subtle text-success border border-success' ;
53+ statusDiv . style . backgroundColor = '#d1e7dd' ;
54+ } else if ( val2 === '' ) {
55+ statusDiv . style . display = 'none' ;
56+ } else {
57+ statusDiv . textContent = '✗ Passwords do not match' ;
58+ statusDiv . className = 'small mt-2 text-center py-1 rounded bg-danger-subtle text-danger border border-danger' ;
59+ statusDiv . style . backgroundColor = '#f8d7da' ;
60+ }
61+ }
62+
63+ newPassword . addEventListener ( 'input' , updateStatus ) ;
64+ confirmPassword . addEventListener ( 'input' , updateStatus ) ;
65+ }
66+
3067// Theme Management
3168function loadTheme ( ) {
3269 const savedTheme = localStorage . getItem ( 'theme' ) ;
@@ -68,7 +105,7 @@ function initializeFormValidation() {
68105 // Password confirmation validation
69106 const passwordInputs = document . querySelectorAll ( 'input[name="confirm_password"]' ) ;
70107 passwordInputs . forEach ( input => {
71- input . addEventListener ( 'input' , validatePasswordMatch ) ;
108+ // Validation moved to form submission to prevent premature error messages
72109 } ) ;
73110
74111 // Form submission validation
@@ -99,8 +136,19 @@ function validateEmailRealTime(event) {
99136}
100137
101138function validatePasswordMatch ( event ) {
139+ if ( ! event || ! event . target ) return true ;
140+
102141 const confirmPassword = event . target . value ;
103- const password = document . querySelector ( 'input[name="password"]' ) . value ;
142+ const passwordElement = document . querySelector ( 'input[name="password"]' ) ||
143+ document . querySelector ( 'input[name="new_password"]' ) ||
144+ document . getElementById ( 'new_password' ) ;
145+
146+ if ( ! passwordElement ) {
147+ console . warn ( 'Password element not found for matching' ) ;
148+ return true ;
149+ }
150+
151+ const password = passwordElement . value || '' ;
104152
105153 if ( confirmPassword && password !== confirmPassword ) {
106154 showFieldError ( event . target , 'Passwords do not match' ) ;
0 commit comments