lisichatbot 1.3.9 → 1.4.0

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 +77 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.3.9",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -1331,10 +1331,21 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
1331
1331
  inputElement.type = inputType === 'number' ? 'number' : 'text';
1332
1332
 
1333
1333
  inputElement.oninput = (e) => {
1334
- const value = inputType === 'number' ? parseFloat(e.target.value) : e.target.value;
1334
+ const rawValue = e.target.value;
1335
+ const value = inputType === 'number' ? parseFloat(rawValue) : rawValue;
1335
1336
 
1336
- chatState.data[field] = value;
1337
- chatState.currentSelection = { field, value, name: value.toString() };
1337
+ // ✅ FIX: Only set data and currentSelection if value is valid
1338
+ const isEmpty = rawValue === '' || (inputType === 'number' && isNaN(value));
1339
+ const isEmptyText = inputType === 'text' && (!rawValue || rawValue.trim() === '');
1340
+
1341
+ if (!isEmpty && !isEmptyText) {
1342
+ chatState.data[field] = value;
1343
+ chatState.currentSelection = { field, value, name: value.toString() };
1344
+ } else {
1345
+ // Clear data and selection for empty values
1346
+ delete chatState.data[field];
1347
+ chatState.currentSelection = null;
1348
+ }
1338
1349
 
1339
1350
  if (hasValidation) {
1340
1351
  const min = inputConfig.min;
@@ -1343,7 +1354,7 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
1343
1354
  let isValid = true;
1344
1355
  let errorMessage = '';
1345
1356
 
1346
- if (e.target.value === '' || (inputType === 'number' && isNaN(value))) {
1357
+ if (rawValue === '' || (inputType === 'number' && isNaN(value))) {
1347
1358
  isValid = false;
1348
1359
  errorMessage = 'Please enter a valid number';
1349
1360
  } else if (min !== undefined && value < min) {
@@ -1362,21 +1373,43 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
1362
1373
  console.log(` ❌ Number input invalid: ${errorMessage} - Next button disabled`);
1363
1374
  }
1364
1375
  } else {
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`);
1376
+ // ✅ FIX: Handle number inputs without validation
1377
+ if (inputType === 'number') {
1378
+ // For number inputs, check if value is valid
1379
+ if (rawValue === '' || isNaN(value)) {
1380
+ // Empty or NaN
1381
+ const currentStep = flowData.flow[chatState.step];
1382
+ const inputRequired = currentStep.inputRequired === true;
1383
+
1384
+ if (inputRequired) {
1385
+ disableNextButton();
1386
+ console.log(` 🔒 Number input empty/NaN and required - Next button disabled`);
1387
+ } else {
1388
+ enableNextButton();
1389
+ console.log(` 🔓 Number input empty/NaN but not required - Next button enabled`);
1390
+ }
1377
1391
  } else {
1392
+ // Has valid number value
1378
1393
  enableNextButton();
1379
- console.log(` 🔓 Text input empty but not required - Next button enabled`);
1394
+ console.log(` Number input has value: ${value} - Next button enabled`);
1395
+ }
1396
+ } else {
1397
+ // Text input logic
1398
+ if (rawValue && rawValue.trim() !== '') {
1399
+ enableNextButton();
1400
+ console.log(` ✅ Text input has value - Next button enabled`);
1401
+ } else {
1402
+ // ✅ Check if input is required
1403
+ const currentStep = flowData.flow[chatState.step];
1404
+ const inputRequired = currentStep.inputRequired === true;
1405
+
1406
+ if (inputRequired) {
1407
+ disableNextButton();
1408
+ console.log(` 🔒 Text input empty and required - Next button disabled`);
1409
+ } else {
1410
+ enableNextButton();
1411
+ console.log(` 🔓 Text input empty but not required - Next button enabled`);
1412
+ }
1380
1413
  }
1381
1414
  }
1382
1415
  }
@@ -1516,6 +1549,33 @@ async function handleNext() {
1516
1549
  console.log('Selection required but none made');
1517
1550
  return;
1518
1551
  }
1552
+
1553
+ // ✅ FIX: Validate text/number inputs when required
1554
+ if (currentStep.input && inputRequired) {
1555
+ const inputType = currentStep.inputType || 'single-select';
1556
+
1557
+ if (inputType === 'text' || inputType === 'number') {
1558
+ const field = currentStep.input.field;
1559
+ const value = chatState.data[field];
1560
+
1561
+ // Check for empty or invalid values
1562
+ if (inputType === 'text') {
1563
+ if (value === undefined || value === null || value === '' || (typeof value === 'string' && value.trim() === '')) {
1564
+ console.log('❌ Text input required but empty - cannot proceed');
1565
+ disableNextButton();
1566
+ return;
1567
+ }
1568
+ } else if (inputType === 'number') {
1569
+ if (value === undefined || value === null || value === '' || isNaN(value)) {
1570
+ console.log('❌ Number input required but empty/NaN - cannot proceed');
1571
+ disableNextButton();
1572
+ return;
1573
+ }
1574
+ }
1575
+
1576
+ console.log(`✅ ${inputType} input validation passed:`, value);
1577
+ }
1578
+ }
1519
1579
 
1520
1580
  if (currentStep.inputType === 'single-select-custom' && currentStep.input) {
1521
1581
  const field = currentStep.input.field;