Merge pull request #176 from Lawrr/fix-text-serialize-value

Fix text values returning "undefined" and not failing validation
This commit is contained in:
pythongosssss
2024-01-31 19:34:34 +00:00
committed by GitHub
+17 -10
View File
@@ -196,22 +196,29 @@ app.registerExtension({
return prompt;
},
];
if (widget.serializeValue) {
callbacks.push(widget.serializeValue);
}
let inheritedSerializeValue = widget.serializeValue || null;
let called = false;
const serializeValue = async (workflowNode, widgetIndex) => {
const widgetValue = widget.value;
if (called) return widgetValue;
const origWidgetValue = widget.value;
if (called) return origWidgetValue;
called = true;
for (const cb of callbacks) {
widget.value = await cb(workflowNode, widgetIndex);
let allCallbacks = [...callbacks];
if (inheritedSerializeValue) {
allCallbacks.push(inheritedSerializeValue)
}
let valueIsUndefined = false;
for (const cb of allCallbacks) {
let value = await cb(workflowNode, widgetIndex);
// Need to check the callback return value before it is set on widget.value as it coerces it to a string (even for undefined)
if (value === undefined) valueIsUndefined = true;
widget.value = value;
}
const prompt = widget.value;
widget.value = widgetValue;
const prompt = valueIsUndefined ? undefined : widget.value;
widget.value = origWidgetValue;
called = false;
@@ -223,7 +230,7 @@ app.registerExtension({
return serializeValue;
},
set(cb) {
callbacks.push(cb);
inheritedSerializeValue = cb;
},
});
}