justpy
justpy copied to clipboard
deleted components show up at button callback
I am refreshing portions (div
, contains the configuration section) of a page by periodically deleting the div's content using delete_components
, re-creating it (from fresh data) and calling jp.run_task(wp.update())
afterwards. This works well (no flickering or anything).
The moment I click a button, however, the div appears with the content twice (as if not deleted, maybe it is the previous content somehow hanging around?), until the page refreshes itself again, as shown in the video. The self.update()
is only called explicitly from within the periodic refresher.
Is that something known (and workaroundable) or should I provide a MWE?
An example would be very helpful, if possible.
Here you go :)
import justpy as jp
import asyncio
@jp.SetRoute('/')
class MainPage(jp.QuasarPage):
def __init__(self):
super().__init__(delete_flag=False)
self.div=jp.Div(a=self)
self.butt=jp.QButton(text='Button',a=self)
self.butt.on('click',self.onButtClick)
jp.run_task(self.pageUpdater())
def onButtClick(self,b):
return
async def pageUpdater(self):
while True:
self.div.delete_components()
jp.QMarkupTable(a=self.div,children=[jp.AutoTable(values=[['A','B','C','D'],['1','2','3','4']])])
jp.run_task(self.update())
await asyncio.sleep(1)
jp.justpy()
It is a weird bug. For now, I don't have an answer as to why this is happening but there is a simple workaround. Change onButtClitck to:
def onButtClick(self,b):
return True
This will cause the page not to update once the click event handler is done running.
Confirming that returning True
from the handler (in the MWE and also in the more complicated script I use) prevents the refresh from happening. Thanks :)