Manolo Santos
Manolo Santos14mo ago

set the value of a text_area programmatically

Hi! is it there a way to set the value of a text_area programmatically. I have a text_area that I want to pre-populate depending on the selected row of a table, but I want to optionally modify it before sending it. If I modify it, everything works, but if I don't, the value (internal) is stale, despite being shown properly.
1 Reply
Myles Scolnick
Myles Scolnick14mo ago
hi @Manolo Santos , you can use mo.state to manage the state of the text area outside of the UI element. for example:
# Cell 1
get_text, set_test = mo.state("")

# Cell 2
mo.ui.text_area(value=get_value(), on_change=set_value)

# Cell 3
mo.ui.table(on_change=lambda v: set_value(v[0]["Column"]))
# Cell 1
get_text, set_test = mo.state("")

# Cell 2
mo.ui.text_area(value=get_value(), on_change=set_value)

# Cell 3
mo.ui.table(on_change=lambda v: set_value(v[0]["Column"]))
let me know if you have any issues with that