-
QuestionSample code ( I use @dataclass
class TFStruct:
ref: ft.Ref[ft.TextField] # input ref
label: str # input label
value: str # input value
class FlVar:
"""Define some static variable"""
HValues: list[str] = [...]
TfRefs: list[TFStruct] = [TFStruct(ft.Ref[ft.TextField](), h, '') for h in HValues]
def addTF(label, value, ref, i):
return ft.TextField(
label=label,
ref=ref,
text_size=16,
on_change=inputChanged,
read_only=True if i > 7 else False,
value=FlText.PLACEHOLDER_DEFAULT if i > 7 else value,
max_length=FlVar.TEXT_LENGTH_1 if i < 2 else FlVar.TEXT_LENGTH_2,
keyboard_type='number' if label != Header.Name.value else 'none',
)
textFileds = [
addTF(item.label, item.value, item.ref, i)
for i, item in enumerate(FlVar.TfRefs)
]
# Finally use like this
page.add(
ft.Container(ft.Column(textFileds))
)
for i, item in enumerate(FlVar.TfRefs):
irc = item.ref.current
print(irc.value) Finally, get the value and set the value through the for loop, which is convenient for debugging. I can read and write yesterday, but now no matter how I debug, the value I get is still a null character (like I don't know why, is there something wrong with my code? Code sampleNo response Error messageNo response ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Please share some runnable code. I got alot of errors (several stuffs are undefined) when running this. |
Beta Was this translation helpful? Give feedback.
-
Your code is not correct. The parentheses are missing at the end of the statement. Your code: ref: ft.Ref[ft.TextField] Correct code: ref: ft.Ref[ft.TextField] () |
Beta Was this translation helpful? Give feedback.
-
I have been debugging this problem for a long time |
Beta Was this translation helpful? Give feedback.
I have been debugging this problem for a long time
gained experience:
My component is dynamically loaded and then the ref variable is also dynamically loaded, something like "Tab" 切换
When the custom control is toggled, the control is not "visible" properly, so the
ref
doesn't work.