Unable to change .content value of ui.text() components within ui.section card #2209
-
Hi!I am trying to update values of ui.text() based on selecting user id from a dropdown list. I am trying to access by component name but It isnt working. It works when i delete and redraw the card with updated values but not otherwise. Sharing a sample example to illustrate the same. Thank you!
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi!
Please make a minimal repro example then. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi @n-srinidhi! Your textbox has the name To @mturoci's point, I did strip down a lot of your example to be able to get to the root cause. Here's what I might have shared an an MRE from h2o_wave import main, app, Q, ui, data, run_on, on
# Sample Data
user_info = {'101': {'preferred_hour': '6'}, '102': {'preferred_hour': '7'}, '103': {'preferred_hour': '8'}, '104': {'preferred_hour': '9'}}
@app('/')
async def serve(q: Q):
if not q.client.initialized:
q.client.user_id = list(user_info.keys())[0]
q.page['top_section'] = ui.section_card(
title='',
subtitle='',
box="1 1 1 1",
items=[
ui.text(name='user_stat1_val', content="15"),
ui.dropdown(name='select_user_id', label='',
choices=[ui.choice(name=x, label=x) for x in user_info.keys()],
value=q.client.user_id, trigger=True)
]
)
q.client.initialized = True
else:
q.client.user_id = q.args.select_user_id
q.page['top_section'].user_stat1_val.content = str(user_info[q.client.user_id]['preferred_hour'])
await q.page.save() @mturoci This is good feedback that getting a console warning when you try to update a card that does not exist could be super helpful to devs. WDYT? |
Beta Was this translation helpful? Give feedback.
Hi @n-srinidhi!
Your textbox has the name
user_stat1_val
, but in your update code you haveq.page['top_section'].user_stat_1_val.content
(note the extra underscore). When I updated the variables to match, the code worked.To @mturoci's point, I did strip down a lot of your example to be able to get to the root cause. Here's what I might have shared an an MRE