From c96e7b3e17355e8d5cbea1ea8190414f4fe96d2e Mon Sep 17 00:00:00 2001
From: enured <enis.nuredini@uzh.ch>
Date: Sat, 30 Dec 2023 16:04:34 +0100
Subject: [PATCH] B17462: Chat Implementation V1.3  refs #17462

---
 extension/Classes/Core/AbstractBuildForm.php | 3 ++-
 javascript/src/Core/FormGroup.js             | 4 ++++
 javascript/src/Helper/qfqChat.js             | 6 ++++++
 javascript/src/QfqForm.js                    | 3 ++-
 4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/extension/Classes/Core/AbstractBuildForm.php b/extension/Classes/Core/AbstractBuildForm.php
index ecb21a67b..6d9ceeed6 100644
--- a/extension/Classes/Core/AbstractBuildForm.php
+++ b/extension/Classes/Core/AbstractBuildForm.php
@@ -3161,7 +3161,7 @@ abstract class AbstractBuildForm {
 
         $chatFieldsetStart = '<fieldset ' . $fieldsetAttribute . '>';
 
-        if ($formElement[FE_LABEL] !== '') {
+        if ($formElement[FE_LABEL] !== '' && $formElement[FE_BS_LABEL_COLUMNS] == 0) {
             $chatFieldsetStart .= '<legend>' . $formElement[FE_LABEL] . '</legend>';
         }
         $chatFieldsetEnd = '</fieldset>';
@@ -3251,6 +3251,7 @@ abstract class AbstractBuildForm {
 
         $inputAttribute .= Support::doAttribute('cols', $colsRows[0]);
         $inputAttribute .= Support::doAttribute('rows', $colsRows[1]);
+        $inputAttribute .= Support::doAttribute('id', $formElement[FE_HTML_ID] . '-chat-i');
 
         // Check if $colsRows[2] != 0 >> enable auto-grow (if nothing is defined: enable auto-grow)
         $maxHeight = $colsRows[2] ?? '350';
diff --git a/javascript/src/Core/FormGroup.js b/javascript/src/Core/FormGroup.js
index 7d707635e..f536d63ed 100644
--- a/javascript/src/Core/FormGroup.js
+++ b/javascript/src/Core/FormGroup.js
@@ -95,6 +95,10 @@ QfqNS.Element = QfqNS.Element || {};
         var idArray = $enclosedElement.attr('id').split("-");
         var searchString = "#";
         for(var i = 0; i < 8 && i < idArray.length; i++) {
+            // Handle form-group for chat input element
+            if (idArray[i] === 'chat') {
+                continue;
+            }
             searchString += idArray[i] + "-";
         }
         var $formGroup = $(searchString + 'i');
diff --git a/javascript/src/Helper/qfqChat.js b/javascript/src/Helper/qfqChat.js
index 64a218728..90ffa9774 100644
--- a/javascript/src/Helper/qfqChat.js
+++ b/javascript/src/Helper/qfqChat.js
@@ -313,6 +313,12 @@ QfqNS.Helper = QfqNS.Helper || {};
         messageElement.scrollTo({ top: messageElement.scrollHeight, behavior: 'smooth' });
     };
 
+    qfqChat.setInputState = function (element, configItem) {
+        let inputElement = element.nextElementSibling;
+        inputElement.disabled = configItem.disabled;
+        inputElement.required = configItem.required;
+    }
+
     qfqChat.createNewMessage = function (key, chatConfig) {
         let chatContainerElement = document.createElement('div');
         chatContainerElement.className = 'chat-container ' + chatConfig.bubbleClass;
diff --git a/javascript/src/QfqForm.js b/javascript/src/QfqForm.js
index 32dd536ce..105fabeb3 100644
--- a/javascript/src/QfqForm.js
+++ b/javascript/src/QfqForm.js
@@ -1418,8 +1418,9 @@ var QfqNS = QfqNS || {};
 
                     // Chats needs to be loaded with new data
                     // It refreshes the output
-                    if (element.classList.contains('qfq-chat-window') && configurationItem.chat !== undefined) {
+                    if (element.classList !== undefined && element.classList.contains('qfq-chat-window') && configurationItem.chat !== undefined) {
                         n.Helper.qfqChat.refreshChat(element, configurationItem.chat);
+                        n.Helper.qfqChat.setInputState(element, configurationItem);
                     }
                 }
 
-- 
GitLab