Why is the entire value of a textarea constantly sent to the server on every key press? #4044
Answered
by
falkoschindler
umarbutler
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
falkoschindler
Nov 28, 2024
Replies: 1 comment
-
Hi @umarbutler, It was one of NiceGUI's central design decisions to always synchronize state with the server to allow other parts of the code to access current values, handle events, validate inputs etc. In some cases this can indeed cause a significant overhead. Elements like class MyTextarea(ui.element):
def __init__(self, value: str = '') -> None:
super().__init__(tag='q-input')
self._props['type'] = 'textarea'
self._props['model-value'] = value
async def get_value(self) -> str:
return await ui.run_javascript(f'return getElement({self.id}).modelValue')
@ui.page('/')
def page():
async def submit():
ui.notify(await text.get_value())
text = MyTextarea('Hello')
ui.button('Submit', on_click=submit) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
umarbutler
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @umarbutler,
It was one of NiceGUI's central design decisions to always synchronize state with the server to allow other parts of the code to access current values, handle events, validate inputs etc. In some cases this can indeed cause a significant overhead. Elements like
ui.log
,ui.scene
orui.codemirror
avoid it by sending updates rather than the whole state. And for text areas you can derive your own element from Quasar's QInput and request the current model value on demand: