Open aranvir opened 7 months ago
Hello,
Thank you for all the details! While this bug and resolution are discussed, I wanted to let you know about copy_expando
which might help if you are currently blocked.
You are currently doing a lot of work in the Query Arguments q.args
variable, but you are looking at content for each browser session that you want to access across many calls. Instead, it would be preferred to use the q.client
variable. These will persist across interactions in the client session, and be separate for each browser session.
You can assign each args to a client in your popup_send
function.
...
q.client.popup_input_3 = q.args.popup_input_3
Or, if your form gets long and this is tedious, you can copy all values from q.args into q.client such as
from h2o_wave import ... copy_expando
@app('/')
async def serve(q: Q):
copy_expando(q.args, q.client)
...
# replace all q.args.variable with q.client.variable
Hope this helps!
Hi, thanks for the feedback! I am using q.client
to buffer certain things but was not aware of copy_expando
. That looks like a good workaround for my actual use case where I generate the input forms dynamically.
Regarding using q.args
a lot: I don't understand why q.client
should be the preferred solution for this. I tend to use q.client
for information I want to persist during the client session over multiple pages and that is not always form related. To me it feels natural to use q.args
to persist data for the current form since I then don't have to worry about cleaning it when I move to the next page/form. There, I did run once into the problem that I was buffering data in q.client
for a form template that I used on multiple pages and thus had to add a reset to that specific buffer just in case.
So, of course that's not a biggy, but with q.args
I could skip these steps :) Still, happy to learn about better alternatives!
Wave SDK Version, OS
Windows 10 Python 3.10.7 h2o-wave 1.0.0
Actual behavior
I'd like to use form verification: At least, check that no input is empty. If at least one input is empty, inform the user and keep all previous inputs. On every submit, all inputs are part of
q.args
. If the form is part of a card, this works fine. If the form is part of a dialog, it gets inconsistent:q.args
and can be passed as values to the reloaded form.q.args
even not those that were visible before in the ui. The ui now also appears empty.q.args
but are now emptyq.args
unless providedConsidering this it can get a extra funny:
Expected behavior
I'd expect a dialog form to behave the same as a regular page form. But I am aware that it is not recommended to use dialogs for "content-heavy" workflows, so I'm also wondering if this behavior is "intended" or just a limitation of how the dialog box is implemented.
Steps To Reproduce
The app has two pages:
Page Form
andDialog Form
On
Page Form
:Send
without any input ->q.args
includes all input fieldsSend
without any input multiple times ->q.args
includes all input fieldsSend
with partial input ->q.args
includes all input fields and the ui shows the previous inputSend
with partial input multiple times->q.args
includes all input fields and the ui shows the previous inputSend
with complete input ->q.args
includes all input fields. The form is submitted and the fields are clearedReset
-> The fields are clearedOn
Dialog Form
:Page Form
Example code: