lisichatbot 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +95 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -1094,7 +1094,52 @@ function handleCustomSelectClick(element, field, customConfig) {
1094
1094
 
1095
1095
  console.log(`Custom-select clicked:`, { field, name: optionName, isCustom });
1096
1096
 
1097
+ // ✅ FIX: Check if this option is already selected - allow deselection
1098
+ const isAlreadySelected = element.classList.contains('cf-checked');
1099
+
1097
1100
  const allOptions = document.querySelectorAll(`[data-field="${field}"][data-chat-element="single-select-input"]`);
1101
+
1102
+ if (isAlreadySelected) {
1103
+ // ✅ Deselect the currently selected option
1104
+ console.log(` 🔄 Deselecting "${optionName}"`);
1105
+
1106
+ element.classList.remove('cf-checked');
1107
+ element.style.setProperty('background-color', 'transparent', 'important');
1108
+ const tickIcon = element.querySelector('[data-chat-input-element="tick-icon"]');
1109
+ if (tickIcon) tickIcon.style.setProperty('display', 'none', 'important');
1110
+
1111
+ // Hide range wrapper if custom was deselected
1112
+ if (isCustom) {
1113
+ const rangeWrapper = document.querySelector(`[data-chat-element="range-wrapper"][data-field="${field}"]`);
1114
+ if (rangeWrapper) {
1115
+ rangeWrapper.style.display = 'none';
1116
+ }
1117
+ }
1118
+
1119
+ // Clear data
1120
+ delete chatState.data[field];
1121
+ chatState.currentSelection = null;
1122
+
1123
+ console.log(` ❌ Deselected "${optionName}" - No selection`);
1124
+
1125
+ // ✅ Check if input is required - disable button if nothing selected
1126
+ const currentStep = flowData.flow[chatState.step];
1127
+ const inputRequired = currentStep.inputRequired === true;
1128
+
1129
+ if (inputRequired) {
1130
+ disableNextButton();
1131
+ console.log(' 🔒 Input required - Next button disabled');
1132
+ } else {
1133
+ enableNextButton();
1134
+ console.log(' 🔓 Input not required - Next button still enabled');
1135
+ }
1136
+
1137
+ return; // Exit early
1138
+ }
1139
+
1140
+ // ✅ Select this option (deselect others first)
1141
+ console.log(` ✅ Selecting "${optionName}"`);
1142
+
1098
1143
  allOptions.forEach(opt => {
1099
1144
  opt.classList.remove('cf-checked');
1100
1145
  opt.style.setProperty('background-color', 'transparent', 'important');
@@ -1542,27 +1587,63 @@ function handleOptionClick(element, field, isSingleSelect) {
1542
1587
  }
1543
1588
 
1544
1589
  if (isSingleSelect) {
1590
+ // ✅ FIX: Check if this option is already selected - allow deselection
1591
+ const isAlreadySelected = element.classList.contains('cf-checked');
1592
+
1545
1593
  const selector = `[data-field="${field}"][data-chat-element="${inputType}"]`;
1546
1594
  const allOptions = document.querySelectorAll(selector);
1547
1595
 
1548
- allOptions.forEach(opt => {
1549
- opt.classList.remove('cf-checked');
1550
- opt.style.setProperty('background-color', 'transparent', 'important');
1596
+ if (isAlreadySelected) {
1597
+ // ✅ Deselect the currently selected option
1598
+ console.log(` 🔄 Deselecting "${optionName}"`);
1599
+
1600
+ element.classList.remove('cf-checked');
1601
+ element.style.setProperty('background-color', 'transparent', 'important');
1602
+ if (tickIcon) tickIcon.style.setProperty('display', 'none', 'important');
1603
+ if (input) input.checked = false;
1551
1604
 
1552
- const otherTick = opt.querySelector('[data-chat-input-element="tick-icon"]');
1553
- const otherInput = opt.querySelector('[data-chat-input-element="input"]');
1605
+ // Clear data
1606
+ delete chatState.data[field];
1607
+ chatState.currentSelection = null;
1554
1608
 
1555
- if (otherTick) otherTick.style.setProperty('display', 'none', 'important');
1556
- if (otherInput) otherInput.checked = false;
1557
- });
1609
+ console.log(` ❌ Deselected "${optionName}" - No selection`);
1610
+
1611
+ // ✅ Check if input is required - disable button if nothing selected
1612
+ const currentStep = flowData.flow[chatState.step];
1613
+ const inputRequired = currentStep.inputRequired === true;
1614
+
1615
+ if (inputRequired) {
1616
+ disableNextButton();
1617
+ console.log(' 🔒 Input required - Next button disabled');
1618
+ } else {
1619
+ enableNextButton();
1620
+ console.log(' 🔓 Input not required - Next button still enabled');
1621
+ }
1622
+ } else {
1623
+ // ✅ Select this option (deselect others first)
1624
+ console.log(` ✅ Selecting "${optionName}"`);
1625
+
1626
+ allOptions.forEach(opt => {
1627
+ opt.classList.remove('cf-checked');
1628
+ opt.style.setProperty('background-color', 'transparent', 'important');
1629
+
1630
+ const otherTick = opt.querySelector('[data-chat-input-element="tick-icon"]');
1631
+ const otherInput = opt.querySelector('[data-chat-input-element="input"]');
1632
+
1633
+ if (otherTick) otherTick.style.setProperty('display', 'none', 'important');
1634
+ if (otherInput) otherInput.checked = false;
1635
+ });
1558
1636
 
1559
- element.classList.add('cf-checked');
1560
- element.style.setProperty('background-color', config.selectedBackground, 'important');
1561
- if (tickIcon) tickIcon.style.setProperty('display', 'block', 'important');
1562
- if (input) input.checked = true;
1637
+ element.classList.add('cf-checked');
1638
+ element.style.setProperty('background-color', config.selectedBackground, 'important');
1639
+ if (tickIcon) tickIcon.style.setProperty('display', 'block', 'important');
1640
+ if (input) input.checked = true;
1563
1641
 
1564
- chatState.data[field] = value;
1565
- chatState.currentSelection = { field, value, name: optionName };
1642
+ chatState.data[field] = value;
1643
+ chatState.currentSelection = { field, value, name: optionName };
1644
+
1645
+ enableNextButton();
1646
+ }
1566
1647
 
1567
1648
  } else {
1568
1649
  const isChecked = !element.classList.contains('cf-checked');