h2oai / wave

Realtime Web Apps and Dashboards for Python and R
https://wave.h2o.ai
Apache License 2.0
3.98k stars 328 forks source link

Keep cursor active in textbox after textbox trigger #2295

Closed g-eoj closed 6 months ago

g-eoj commented 6 months ago

Is your feature request related to a problem? Please describe

When typing in a textbox, if the trigger fires before I'm done typing, I have to reselect the textbox with my mouse to continue typing.

Describe the solution you'd like

Keep the textbox active upon a trigger.

mturoci commented 6 months ago

Hi @g-eoj,

I assume the reason you are experiencing losing focus is due to textbox recreation instead of just value update. @marek-mihok please verify.

marek-mihok commented 6 months ago

Your assumption is correct, @mturoci.

https://github.com/h2oai/wave/assets/23740173/85cabed8-02f6-419c-b662-0f12c2244ac1

mturoci commented 6 months ago

Please paste the code for @g-eoj here so that he has better time copy pasting the code and understanding what needs to be changed.

g-eoj commented 6 months ago

I got it to work. Thank you!

marek-mihok commented 6 months ago

@g-eoj perfect! I'm pasting the code anyway if someone in future will look for this issue.

from h2o_wave import main, app, Q, ui

@app('/demo')
async def serve(q: Q):
    # Make sure textbox is created only once by using `q.client.initialized`:
    if not q.client.initialized:
        q.page['example'] = ui.form_card(box='1 1 -1 -1', items=[
            ui.textbox(name='textbox_trigger', label='Textbox with trigger', trigger=True),
            ui.text(name='textbox_trigger_value', content=''),
        ])
        q.client.initialized = True

    if q.args.textbox_trigger is not None:
        q.page['example'].textbox_trigger_value.content = q.args.textbox_trigger

    await q.page.save()