lisichatbot 1.3.8 → 1.3.9

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 +58 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -58,16 +58,18 @@ function scrollToBottom() {
58
58
  function enableNextButton() {
59
59
  if (elements.nextBtn) {
60
60
  elements.nextBtn.disabled = false;
61
- elements.nextBtn.style.opacity = '1';
62
- elements.nextBtn.style.cursor = 'pointer';
61
+ elements.nextBtn.style.setProperty('opacity', '1', 'important');
62
+ elements.nextBtn.style.setProperty('cursor', 'pointer', 'important');
63
+ console.log(' ✅ Next button ENABLED (opacity: 1, cursor: pointer)');
63
64
  }
64
65
  }
65
66
 
66
67
  function disableNextButton() {
67
68
  if (elements.nextBtn) {
68
69
  elements.nextBtn.disabled = true;
69
- elements.nextBtn.style.opacity = '0.5';
70
- elements.nextBtn.style.cursor = 'not-allowed';
70
+ elements.nextBtn.style.setProperty('opacity', '0.5', 'important');
71
+ elements.nextBtn.style.setProperty('cursor', 'not-allowed', 'important');
72
+ console.log(' 🔒 Next button DISABLED (opacity: 0.5, cursor: not-allowed)');
71
73
  }
72
74
  }
73
75
 
@@ -1275,9 +1277,19 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
1275
1277
  }
1276
1278
  }
1277
1279
 
1278
- if (existingValue !== undefined && existingValue !== null) {
1280
+ // FIX: Handle pre-filled values for both validation and non-validation cases
1281
+ const hasValue = existingValue !== undefined && existingValue !== null && existingValue !== '';
1282
+
1283
+ if (hasValue) {
1279
1284
  inputElement.value = existingValue;
1280
- console.log(` ✅ Pre-filled with: ${existingValue}`);
1285
+ console.log(` ✅ Pre-filled with: "${existingValue}"`);
1286
+
1287
+ // Set currentSelection for pre-filled value
1288
+ chatState.currentSelection = {
1289
+ field,
1290
+ value: existingValue,
1291
+ name: existingValue.toString()
1292
+ };
1281
1293
 
1282
1294
  if (hasValidation) {
1283
1295
  const value = parseFloat(existingValue);
@@ -1290,14 +1302,30 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
1290
1302
 
1291
1303
  if (isValid) {
1292
1304
  enableNextButton();
1293
- console.log(` ✅ Pre-filled value is valid: ${value}`);
1305
+ console.log(` ✅ Pre-filled number is valid - Next button enabled`);
1294
1306
  } else {
1295
1307
  disableNextButton();
1296
- console.log(` ❌ Pre-filled value is invalid: ${value}`);
1308
+ console.log(` ❌ Pre-filled number is invalid - Next button disabled`);
1297
1309
  }
1310
+ } else {
1311
+ // ✅ FIX: Enable button for pre-filled text input
1312
+ enableNextButton();
1313
+ console.log(` ✅ Pre-filled text - Next button enabled`);
1298
1314
  }
1299
1315
  } else {
1316
+ // ✅ No pre-filled value - set initial button state
1300
1317
  inputElement.value = '';
1318
+
1319
+ const currentStep = flowData.flow[chatState.step];
1320
+ const inputRequired = currentStep.inputRequired === true;
1321
+
1322
+ if (inputRequired || hasValidation) {
1323
+ disableNextButton();
1324
+ console.log(` 🔒 Empty input (required or has validation) - Next button disabled`);
1325
+ } else {
1326
+ enableNextButton();
1327
+ console.log(` 🔓 Empty input (optional, no validation) - Next button enabled`);
1328
+ }
1301
1329
  }
1302
1330
 
1303
1331
  inputElement.type = inputType === 'number' ? 'number' : 'text';
@@ -1306,7 +1334,7 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
1306
1334
  const value = inputType === 'number' ? parseFloat(e.target.value) : e.target.value;
1307
1335
 
1308
1336
  chatState.data[field] = value;
1309
- chatState.currentSelection = { field, value, name: value };
1337
+ chatState.currentSelection = { field, value, name: value.toString() };
1310
1338
 
1311
1339
  if (hasValidation) {
1312
1340
  const min = inputConfig.min;
@@ -1315,7 +1343,7 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
1315
1343
  let isValid = true;
1316
1344
  let errorMessage = '';
1317
1345
 
1318
- if (value === '' || isNaN(value)) {
1346
+ if (e.target.value === '' || (inputType === 'number' && isNaN(value))) {
1319
1347
  isValid = false;
1320
1348
  errorMessage = 'Please enter a valid number';
1321
1349
  } else if (min !== undefined && value < min) {
@@ -1328,13 +1356,29 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
1328
1356
 
1329
1357
  if (isValid) {
1330
1358
  enableNextButton();
1331
- console.log(` ✅ Number input valid: ${value}`);
1359
+ console.log(` ✅ Number input valid: ${value} - Next button enabled`);
1332
1360
  } else {
1333
1361
  disableNextButton();
1334
- console.log(` ❌ Number input invalid: ${errorMessage}`);
1362
+ console.log(` ❌ Number input invalid: ${errorMessage} - Next button disabled`);
1335
1363
  }
1336
1364
  } else {
1337
- console.log(` 📝 Input updated: ${value} (no validation)`);
1365
+ // FIX: For text inputs without validation, enable button as user types
1366
+ if (e.target.value && e.target.value.trim() !== '') {
1367
+ enableNextButton();
1368
+ console.log(` ✅ Text input has value - Next button enabled`);
1369
+ } else {
1370
+ // ✅ Check if input is required
1371
+ const currentStep = flowData.flow[chatState.step];
1372
+ const inputRequired = currentStep.inputRequired === true;
1373
+
1374
+ if (inputRequired) {
1375
+ disableNextButton();
1376
+ console.log(` 🔒 Text input empty and required - Next button disabled`);
1377
+ } else {
1378
+ enableNextButton();
1379
+ console.log(` 🔓 Text input empty but not required - Next button enabled`);
1380
+ }
1381
+ }
1338
1382
  }
1339
1383
  };
1340
1384
  }
@@ -1655,18 +1699,8 @@ async function showNextStep() {
1655
1699
  const inputType = nextStep.inputType || 'single-select';
1656
1700
 
1657
1701
  if (inputType === 'text' || inputType === 'number') {
1702
+ // ✅ renderTextInput handles ALL button state logic (pre-filled, typing, validation)
1658
1703
  renderTextInput(nextStep.input.field, inputType, nextStep.input);
1659
-
1660
- const hasValidation = inputType === 'number' &&
1661
- (nextStep.input.min !== undefined || nextStep.input.max !== undefined);
1662
-
1663
- if (inputRequired || hasValidation) {
1664
- disableNextButton();
1665
- console.log(' 🔒 Next button disabled initially (input required or validation enabled)');
1666
- } else {
1667
- enableNextButton();
1668
- console.log(' 🔓 Next button enabled (optional input, no validation)');
1669
- }
1670
1704
  } else if (inputType === 'multi-select-color') {
1671
1705
  renderColorOptions(nextStep.input.options, nextStep.input.field);
1672
1706