Add missing submitChatAnswerFromInput method to handle dynamic input areas when AI asks follow-up questions

This commit is contained in:
root
2025-06-30 13:06:27 +02:00
parent d314a96478
commit 902dd284ce

View File

@@ -687,8 +687,16 @@ class KidsAIExplorer {
// For pure "don't know" responses with Socratic guidance, continue to next question immediately
this.continueToNextQuestion();
} else {
// For substantial answers, show choice buttons
this.addContinueChoiceButtons();
// Check if AI response contains a question that needs answering
const hasQuestion = data.response && data.response.includes('?');
if (hasQuestion) {
// AI asked a follow-up question, provide input area
this.addUserInputArea();
} else {
// No question in response, show choice buttons
this.addContinueChoiceButtons();
}
}
}, 1500);
} else {
@@ -1100,6 +1108,13 @@ class KidsAIExplorer {
// Add input area for user to respond
addUserInputArea() {
// Remove any existing input areas to avoid duplicates
const existingInputs = this.conversationContainer.querySelectorAll('.user-input-container');
existingInputs.forEach(input => input.remove());
// Generate unique ID for this input
const inputId = `chat-input-${Date.now()}`;
const inputContainer = document.createElement('div');
inputContainer.className = 'user-input-container';
inputContainer.innerHTML = `
@@ -1107,9 +1122,9 @@ class KidsAIExplorer {
<p>💭 ${this.getTranslation('share-thoughts') || (this.currentLanguage === 'de' ? 'Teile deine Gedanken mit:' : 'Share your thoughts:')}</p>
</div>
<div class="input-area">
<textarea id="chat-input" placeholder="${this.getTranslation('type-thoughts') || (this.currentLanguage === 'de' ? 'Schreibe hier deine Gedanken...' : 'Type your thoughts here...')}"
<textarea id="${inputId}" placeholder="${this.getTranslation('type-thoughts') || (this.currentLanguage === 'de' ? 'Schreibe hier deine Gedanken...' : 'Type your thoughts here...')}"
rows="3" style="width: 100%; padding: 10px; border-radius: 8px; border: 2px solid #e2e8f0; font-size: 14px;"></textarea>
<button onclick="kidsAI.submitChatAnswer()" class="submit-btn" style="margin-top: 10px; padding: 10px 20px; background: #4ade80; color: white; border: none; border-radius: 8px; cursor: pointer;">
<button onclick="kidsAI.submitChatAnswerFromInput('${inputId}')" class="submit-btn" style="margin-top: 10px; padding: 10px 20px; background: #4ade80; color: white; border: none; border-radius: 8px; cursor: pointer;">
${this.getTranslation('submit') || (this.currentLanguage === 'de' ? 'Abschicken' : 'Submit')} 🚀
</button>
</div>
@@ -1123,18 +1138,18 @@ class KidsAIExplorer {
this.scrollToBottomSmoothly();
// Focus on textarea
const textarea = inputContainer.querySelector('#chat-input');
const textarea = inputContainer.querySelector(`#${inputId}`);
if (textarea) {
textarea.focus();
}
}, 200);
}
// Submit chat answer
submitChatAnswer() {
const textarea = document.getElementById('chat-input');
// Submit chat answer from dynamic input with specific ID
submitChatAnswerFromInput(inputId) {
const textarea = document.getElementById(inputId);
if (!textarea) {
console.error('❌ Chat input not found');
console.error('❌ Chat input not found with ID:', inputId);
return;
}