|
1 |
| -from h2o_wave import main, app, Q, ui, on, handle_on, data |
| 1 | +from h2o_wave import main, app, Q, ui, on, run_on, data |
2 | 2 | from typing import Optional, List
|
3 | 3 |
|
4 | 4 |
|
@@ -112,65 +112,58 @@ async def page3(q: Q):
|
112 | 112 |
|
113 | 113 |
|
114 | 114 | @on('#page4')
|
115 |
| -async def handle_page4(q: Q): |
| 115 | +@on('page4_reset') |
| 116 | +async def page4(q: Q): |
| 117 | + q.page['sidebar'].value = '#page4' |
116 | 118 | # When routing, drop all the cards except of the main ones (header, sidebar, meta).
|
117 |
| - # Since this page is interactive, we want to update its card instead of recreating it every time, so ignore 'form' card on drop. |
| 119 | + # Since this page is interactive, we want to update its card |
| 120 | + # instead of recreating it every time, so ignore 'form' card on drop. |
118 | 121 | clear_cards(q, ['form'])
|
119 | 122 |
|
120 |
| - if q.args.step1: |
121 |
| - # Just update the existing card, do not recreate. |
122 |
| - q.page['form'].items = [ |
123 |
| - ui.stepper(name='stepper', items=[ |
124 |
| - ui.step(label='Step 1'), |
125 |
| - ui.step(label='Step 2'), |
126 |
| - ui.step(label='Step 3'), |
127 |
| - ]), |
128 |
| - ui.textbox(name='textbox2', label='Textbox 1'), |
129 |
| - ui.buttons(justify='end', items=[ |
130 |
| - ui.button(name='step2', label='Next', primary=True), |
131 |
| - ]) |
132 |
| - ] |
133 |
| - elif q.args.step2: |
134 |
| - # Just update the existing card, do not recreate. |
135 |
| - q.page['form'].items = [ |
136 |
| - ui.stepper(name='stepper', items=[ |
137 |
| - ui.step(label='Step 1', done=True), |
138 |
| - ui.step(label='Step 2'), |
139 |
| - ui.step(label='Step 3'), |
140 |
| - ]), |
141 |
| - ui.textbox(name='textbox2', label='Textbox 2'), |
142 |
| - ui.buttons(justify='end', items=[ |
143 |
| - ui.button(name='step1', label='Cancel'), |
144 |
| - ui.button(name='step3', label='Next', primary=True), |
145 |
| - ]) |
146 |
| - ] |
147 |
| - elif q.args.step3: |
148 |
| - # Just update the existing card, do not recreate. |
149 |
| - q.page['form'].items = [ |
150 |
| - ui.stepper(name='stepper', items=[ |
151 |
| - ui.step(label='Step 1', done=True), |
152 |
| - ui.step(label='Step 2', done=True), |
153 |
| - ui.step(label='Step 3'), |
154 |
| - ]), |
155 |
| - ui.textbox(name='textbox3', label='Textbox 3'), |
156 |
| - ui.buttons(justify='end', items=[ |
157 |
| - ui.button(name='step2', label='Cancel'), |
158 |
| - ui.button(name='submit', label='Next', primary=True), |
159 |
| - ]) |
160 |
| - ] |
161 |
| - else: |
162 |
| - # If first time on this page, create the card. |
163 |
| - add_card(q, 'form', ui.form_card(box='vertical', items=[ |
164 |
| - ui.stepper(name='stepper', items=[ |
165 |
| - ui.step(label='Step 1'), |
166 |
| - ui.step(label='Step 2'), |
167 |
| - ui.step(label='Step 3'), |
168 |
| - ]), |
169 |
| - ui.textbox(name='textbox1', label='Textbox 1'), |
170 |
| - ui.buttons(justify='end', items=[ |
171 |
| - ui.button(name='step2', label='Next', primary=True), |
172 |
| - ]), |
173 |
| - ])) |
| 123 | + # If first time on this page, create the card. |
| 124 | + add_card(q, 'form', ui.form_card(box='vertical', items=[ |
| 125 | + ui.stepper(name='stepper', items=[ |
| 126 | + ui.step(label='Step 1'), |
| 127 | + ui.step(label='Step 2'), |
| 128 | + ui.step(label='Step 3'), |
| 129 | + ]), |
| 130 | + ui.textbox(name='textbox1', label='Textbox 1'), |
| 131 | + ui.buttons(justify='end', items=[ |
| 132 | + ui.button(name='page4_step2', label='Next', primary=True), |
| 133 | + ]), |
| 134 | + ])) |
| 135 | + |
| 136 | + |
| 137 | +@on() |
| 138 | +async def page4_step2(q: Q): |
| 139 | + # Just update the existing card, do not recreate. |
| 140 | + q.page['form'].items = [ |
| 141 | + ui.stepper(name='stepper', items=[ |
| 142 | + ui.step(label='Step 1', done=True), |
| 143 | + ui.step(label='Step 2'), |
| 144 | + ui.step(label='Step 3'), |
| 145 | + ]), |
| 146 | + ui.textbox(name='textbox2', label='Textbox 2'), |
| 147 | + ui.buttons(justify='end', items=[ |
| 148 | + ui.button(name='page4_step3', label='Next', primary=True), |
| 149 | + ]) |
| 150 | + ] |
| 151 | + |
| 152 | + |
| 153 | +@on() |
| 154 | +async def page4_step3(q: Q): |
| 155 | + # Just update the existing card, do not recreate. |
| 156 | + q.page['form'].items = [ |
| 157 | + ui.stepper(name='stepper', items=[ |
| 158 | + ui.step(label='Step 1', done=True), |
| 159 | + ui.step(label='Step 2', done=True), |
| 160 | + ui.step(label='Step 3'), |
| 161 | + ]), |
| 162 | + ui.textbox(name='textbox3', label='Textbox 3'), |
| 163 | + ui.buttons(justify='end', items=[ |
| 164 | + ui.button(name='page4_reset', label='Finish', primary=True), |
| 165 | + ]) |
| 166 | + ] |
174 | 167 |
|
175 | 168 |
|
176 | 169 | async def init(q: Q) -> None:
|
@@ -213,6 +206,6 @@ async def serve(q: Q):
|
213 | 206 | q.client.initialized = True
|
214 | 207 |
|
215 | 208 | # Handle routing.
|
216 |
| - await handle_on(q) |
| 209 | + await run_on(q) |
217 | 210 | await q.page.save()
|
218 | 211 |
|
0 commit comments