lisichatbot 1.3.2 ā 1.3.4
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.
- package/package.json +1 -1
- package/src/index.js +39 -21
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -922,6 +922,9 @@ function handleCustomSelectClick(element, field, customConfig) {
|
|
|
922
922
|
function validateMinMax(field, customConfig) {
|
|
923
923
|
console.log(`\nš === VALIDATING MIN/MAX for field: ${field} ===`);
|
|
924
924
|
|
|
925
|
+
// Always use global config errors
|
|
926
|
+
const errors = config.customRangeErrors;
|
|
927
|
+
|
|
925
928
|
// Fixed selectors - input has all attributes on it directly
|
|
926
929
|
const minInput = document.querySelector(`[data-field="${field}"][data-input-type="min"][data-chat-input-element="input"]`);
|
|
927
930
|
const maxInput = document.querySelector(`[data-field="${field}"][data-input-type="max"][data-chat-input-element="input"]`);
|
|
@@ -976,7 +979,7 @@ function validateMinMax(field, customConfig) {
|
|
|
976
979
|
|
|
977
980
|
// 1. Check if only one is filled
|
|
978
981
|
if (minFilled && !maxFilled) {
|
|
979
|
-
const error =
|
|
982
|
+
const error = errors.maxRequired;
|
|
980
983
|
showErrorDiv(error);
|
|
981
984
|
console.log(`ā FAIL: Only min filled`);
|
|
982
985
|
disableNextButton();
|
|
@@ -984,7 +987,7 @@ function validateMinMax(field, customConfig) {
|
|
|
984
987
|
}
|
|
985
988
|
|
|
986
989
|
if (!minFilled && maxFilled) {
|
|
987
|
-
const error =
|
|
990
|
+
const error = errors.minRequired;
|
|
988
991
|
showErrorDiv(error);
|
|
989
992
|
console.log(`ā FAIL: Only max filled`);
|
|
990
993
|
disableNextButton();
|
|
@@ -1003,7 +1006,7 @@ function validateMinMax(field, customConfig) {
|
|
|
1003
1006
|
|
|
1004
1007
|
// 3. Check if values are valid numbers
|
|
1005
1008
|
if (isNaN(minValue) || isNaN(maxValue)) {
|
|
1006
|
-
const error =
|
|
1009
|
+
const error = errors.bothRequired;
|
|
1007
1010
|
showErrorDiv(error);
|
|
1008
1011
|
console.log(`ā FAIL: Invalid numbers (min: ${minValue}, max: ${maxValue})`);
|
|
1009
1012
|
disableNextButton();
|
|
@@ -1013,7 +1016,7 @@ function validateMinMax(field, customConfig) {
|
|
|
1013
1016
|
// 4. Check min constraint
|
|
1014
1017
|
console.log(`š Checking: ${minValue} < ${minConstraint}?`);
|
|
1015
1018
|
if (minValue < minConstraint) {
|
|
1016
|
-
const error =
|
|
1019
|
+
const error = errors.minBelowConstraint.replace('{min}', minConstraint);
|
|
1017
1020
|
showErrorDiv(error);
|
|
1018
1021
|
console.log(`ā FAIL: Min (${minValue}) < constraint (${minConstraint})`);
|
|
1019
1022
|
disableNextButton();
|
|
@@ -1024,7 +1027,7 @@ function validateMinMax(field, customConfig) {
|
|
|
1024
1027
|
// 5. Check max constraint
|
|
1025
1028
|
console.log(`š Checking: ${maxValue} > ${maxConstraint}?`);
|
|
1026
1029
|
if (maxValue > maxConstraint) {
|
|
1027
|
-
const error =
|
|
1030
|
+
const error = errors.maxAboveConstraint.replace('{max}', maxConstraint);
|
|
1028
1031
|
showErrorDiv(error);
|
|
1029
1032
|
console.log(`ā FAIL: Max (${maxValue}) > constraint (${maxConstraint})`);
|
|
1030
1033
|
disableNextButton();
|
|
@@ -1035,7 +1038,7 @@ function validateMinMax(field, customConfig) {
|
|
|
1035
1038
|
// 6. Check min < max
|
|
1036
1039
|
console.log(`š Checking: ${minValue} >= ${maxValue}?`);
|
|
1037
1040
|
if (minValue >= maxValue) {
|
|
1038
|
-
const error =
|
|
1041
|
+
const error = errors.minGreaterThanMax;
|
|
1039
1042
|
showErrorDiv(error);
|
|
1040
1043
|
console.log(`ā FAIL: Min (${minValue}) >= Max (${maxValue})`);
|
|
1041
1044
|
disableNextButton();
|
|
@@ -1370,16 +1373,22 @@ async function handleNext() {
|
|
|
1370
1373
|
console.log(`Field: ${field}`);
|
|
1371
1374
|
console.log(`Custom config:`, customConfig);
|
|
1372
1375
|
|
|
1373
|
-
// Check if
|
|
1376
|
+
// Check if the CUSTOM OPTION is actually selected (not just if value is array)
|
|
1377
|
+
// Regular options can also have array values!
|
|
1378
|
+
const customOptionElement = document.querySelector(
|
|
1379
|
+
`[data-field="${field}"][data-is-custom="true"][data-chat-element="single-select-input"]`
|
|
1380
|
+
);
|
|
1381
|
+
const isCustomOptionSelected = customOptionElement?.classList.contains('cf-checked');
|
|
1382
|
+
|
|
1374
1383
|
const selectedValue = chatState.data[field];
|
|
1375
|
-
const isCustomRange = Array.isArray(selectedValue);
|
|
1376
1384
|
|
|
1377
1385
|
console.log(`Selected value:`, selectedValue);
|
|
1378
|
-
console.log(`Is custom
|
|
1386
|
+
console.log(`Is custom option selected? ${isCustomOptionSelected}`);
|
|
1379
1387
|
|
|
1380
|
-
if (
|
|
1388
|
+
if (isCustomOptionSelected && customConfig) {
|
|
1381
1389
|
// Validate the custom range one more time before proceeding
|
|
1382
1390
|
console.log(`š Running final validation before proceeding...`);
|
|
1391
|
+
|
|
1383
1392
|
const validation = validateMinMax(field, customConfig);
|
|
1384
1393
|
|
|
1385
1394
|
console.log(`Validation result:`, validation);
|
|
@@ -1690,7 +1699,7 @@ function handleCompletion() {
|
|
|
1690
1699
|
// INITIALIZATION
|
|
1691
1700
|
// =============================================================================
|
|
1692
1701
|
|
|
1693
|
-
function init(flowName, flowConfig) {
|
|
1702
|
+
function init(flowName, flowConfig, options = {}) {
|
|
1694
1703
|
// Find container by data-chat-element="chat-wrapper"
|
|
1695
1704
|
elements.container = document.querySelector('[data-chat-element="chat-wrapper"]');
|
|
1696
1705
|
|
|
@@ -1705,10 +1714,24 @@ function init(flowName, flowConfig) {
|
|
|
1705
1714
|
Object.assign(config, flowConfig.config);
|
|
1706
1715
|
}
|
|
1707
1716
|
|
|
1717
|
+
// Merge customRangeErrors - priority: options param > flow object > defaults
|
|
1718
|
+
// 1. First, try flow object customRangeErrors
|
|
1719
|
+
if (flowConfig.customRangeErrors) {
|
|
1720
|
+
console.log('ā
Using custom range errors from flow object');
|
|
1721
|
+
Object.assign(config.customRangeErrors, flowConfig.customRangeErrors);
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
// 2. Then, options parameter (overrides flow object if both provided)
|
|
1725
|
+
if (options.customRangeErrors) {
|
|
1726
|
+
console.log('ā
Using custom range errors from options parameter');
|
|
1727
|
+
Object.assign(config.customRangeErrors, options.customRangeErrors);
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1708
1730
|
console.log('ā
Flow initialized:', {
|
|
1709
1731
|
flowName,
|
|
1710
1732
|
selectedBackground: config.selectedBackground,
|
|
1711
|
-
autoAdvanceDelay: config.autoAdvanceDelay
|
|
1733
|
+
autoAdvanceDelay: config.autoAdvanceDelay,
|
|
1734
|
+
customRangeErrors: config.customRangeErrors
|
|
1712
1735
|
});
|
|
1713
1736
|
|
|
1714
1737
|
// Store flow data
|
|
@@ -1835,15 +1858,10 @@ function editStep(stepNumber) {
|
|
|
1835
1858
|
// Clear history from this step forward
|
|
1836
1859
|
chatState.history = chatState.history.filter(h => h.step < stepNumber);
|
|
1837
1860
|
|
|
1838
|
-
console.log(`
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
if (step.input && step.input.field) {
|
|
1843
|
-
console.log(` Deleting field: ${step.input.field}`);
|
|
1844
|
-
delete chatState.data[step.input.field];
|
|
1845
|
-
}
|
|
1846
|
-
});
|
|
1861
|
+
console.log(` ā
Keeping ALL data intact for editing (no data deleted)`);
|
|
1862
|
+
console.log(` Current data:`, chatState.data);
|
|
1863
|
+
// Don't delete any data - keep everything for pre-filling
|
|
1864
|
+
// Data will be replaced when user submits the edited step
|
|
1847
1865
|
|
|
1848
1866
|
console.log(` Calling goToStep(${stepNumber})...`);
|
|
1849
1867
|
// Go to that step
|