Problem: The previous implementation defined 99 optional inputs in Python and tried to hide/show them in frontend, which didn't work reliably on ComfyUI Windows version - fields like fieldValue_99 remained visible. Solution: Complete refactor to dynamically generate widgets: Backend (TA_AITools.py): - Remove INPUT_LIM and 99 pre-defined optional inputs - Add single 'fieldData' STRING field to store serialized field values - process() parses JSON from fieldData to build fieldInputs Frontend (ta_aitools.js): - Remove complex widget hiding logic - When aiToolsId changes, fetch workflow fields from API - Dynamically create widgets using node.addWidget() - Serialize field values to fieldData on each change - Clean up old widgets when switching workflows Benefits: - No more hidden widgets taking up space - Works reliably on both native and Windows versions - Cleaner code (304 lines removed, 192 added) - Node size automatically adjusts to actual field count
34 lines
838 B
Python
34 lines
838 B
Python
import json
|
|
|
|
|
|
class TAAIToolsNode:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"aiToolsId": ("STRING", {"default": ""}),
|
|
"aiToolsName": ("STRING", {"default": ""}),
|
|
},
|
|
"optional": {
|
|
"fieldData": ("STRING", {"default": "[]", "multiline": True}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("STRUCT",)
|
|
CATEGORY = "TensorArt"
|
|
FUNCTION = "process"
|
|
|
|
def process(self, aiToolsId, aiToolsName, fieldData="[]"):
|
|
if not aiToolsId:
|
|
return {}
|
|
|
|
try:
|
|
fieldInputs = json.loads(fieldData) if fieldData else []
|
|
except json.JSONDecodeError:
|
|
fieldInputs = []
|
|
|
|
return [{"fieldInputs": fieldInputs, "aiToolsId": aiToolsId}]
|