redashghjf commited on
Commit
5f690ea
·
verified ·
1 Parent(s): 0ce61d6

i try to chat with it but the input not submited

Browse files
Files changed (1) hide show
  1. index.html +13 -7
index.html CHANGED
@@ -258,22 +258,29 @@
258
  function scrollToBottom() {
259
  chatContainer.scrollTop = chatContainer.scrollHeight;
260
  }
261
-
262
  // Handle form submission
263
  chatForm.addEventListener('submit', async (e) => {
264
  e.preventDefault();
265
 
266
  const message = userInput.value.trim();
267
- if (!message) return;
268
-
269
- // Add user message
 
 
 
 
 
 
 
 
 
 
270
  addUserMessage(message);
271
  userInput.value = '';
272
 
273
  // Add typing indicator
274
  const typingElement = addBotMessage('', true);
275
-
276
- try {
277
  try {
278
  // Get response from Gemini
279
  const response = await gemini.ask(message, conversationId);
@@ -297,7 +304,6 @@
297
  // Show user-friendly error message
298
  addBotMessage("I'm having trouble connecting right now. Please try again later.");
299
  console.error('Chat error:', error);
300
- }
301
  } catch (error) {
302
  // Remove typing indicator
303
  chatContainer.removeChild(typingElement);
 
258
  function scrollToBottom() {
259
  chatContainer.scrollTop = chatContainer.scrollHeight;
260
  }
 
261
  // Handle form submission
262
  chatForm.addEventListener('submit', async (e) => {
263
  e.preventDefault();
264
 
265
  const message = userInput.value.trim();
266
+ if (!message) {
267
+ userInput.focus();
268
+
269
+ // Ensure form submission works on Enter key
270
+ userInput.addEventListener('keydown', (e) => {
271
+ if (e.key === 'Enter' && !e.shiftKey) {
272
+ e.preventDefault();
273
+ chatForm.dispatchEvent(new Event('submit'));
274
+ }
275
+ });
276
+ return;
277
+ }
278
+ // Add user message
279
  addUserMessage(message);
280
  userInput.value = '';
281
 
282
  // Add typing indicator
283
  const typingElement = addBotMessage('', true);
 
 
284
  try {
285
  // Get response from Gemini
286
  const response = await gemini.ask(message, conversationId);
 
304
  // Show user-friendly error message
305
  addBotMessage("I'm having trouble connecting right now. Please try again later.");
306
  console.error('Chat error:', error);
 
307
  } catch (error) {
308
  // Remove typing indicator
309
  chatContainer.removeChild(typingElement);