amine_dubs commited on
Commit
626d52e
·
1 Parent(s): a583ad7
Files changed (1) hide show
  1. static/script.js +22 -8
static/script.js CHANGED
@@ -44,22 +44,36 @@ window.onload = function() {
44
  if (errorElement) errorElement.style.display = 'none';
45
  if (debugElement) debugElement.style.display = 'none';
46
 
47
- // **Crucial Check:** Verify elements still exist before use
48
- if (!textInput || !sourceLangText || !targetLangText) {
49
- console.error('ERROR: Text form elements became null before accessing value!');
50
- showError('Internal error: Form elements missing unexpectedly.');
51
- return;
 
 
 
 
 
52
  }
 
53
 
54
  // Get values
55
- const text = textInput.value ? textInput.value.trim() : '';
 
56
  if (!text) {
57
  showError('Please enter text to translate');
58
  return;
59
  }
60
 
61
- const sourceLangValue = sourceLangText.value;
62
- const targetLangValue = targetLangText.value;
 
 
 
 
 
 
 
63
 
64
  // Show loading indicator
65
  if (textLoadingElement) textLoadingElement.style.display = 'block';
 
44
  if (errorElement) errorElement.style.display = 'none';
45
  if (debugElement) debugElement.style.display = 'none';
46
 
47
+ // --- CRITICAL RE-FETCH AND CHECK ---
48
+ // Re-fetch the element *right before* using it inside the handler
49
+ const currentTextInput = document.getElementById('text-input');
50
+ console.log('Re-fetched #text-input inside handler:', currentTextInput);
51
+
52
+ // Check if it's null *immediately* before accessing .value
53
+ if (!currentTextInput) {
54
+ console.error('FATAL: document.getElementById(\'text-input\') returned null INSIDE the submit handler!');
55
+ showError('Internal error: Text input element disappeared unexpectedly. Check console.');
56
+ return; // Stop execution
57
  }
58
+ // --- END CRITICAL CHECK ---
59
 
60
  // Get values
61
+ // Use the locally fetched element reference
62
+ const text = currentTextInput.value ? currentTextInput.value.trim() : '';
63
  if (!text) {
64
  showError('Please enter text to translate');
65
  return;
66
  }
67
 
68
+ // Fetch other elements needed here (can also use stored references if they are reliable)
69
+ const sourceLangValue = sourceLangText ? sourceLangText.value : null;
70
+ const targetLangValue = targetLangText ? targetLangText.value : null;
71
+
72
+ if (!sourceLangValue || !targetLangValue) {
73
+ console.error('Source or Target language select element is null inside handler!');
74
+ showError('Internal error: Language select element missing.');
75
+ return;
76
+ }
77
 
78
  // Show loading indicator
79
  if (textLoadingElement) textLoadingElement.style.display = 'block';