Is it possible to block other client code from being executed, or component event handlers from being triggered, until the results of a server code call have been returned?
For example, I am using a server code call to get data from a google spreadsheet, which takes some time to load and parse into a dictionary. I do not want the user to be able to search that dictionary for values until all of the data has been retrieved and loaded into the dictionary, or else he may get the (false) alert that no data was found, when in fact it just has not been loaded yet.
Perhaps adding an animation while your searchable panel is loading/disabled as @david.wylie suggested as #2 would help the user know why they canât enter any searches yet.
Iâm using Background task to retrieve big data sometimes. It can run even for long time.
So my first code add a small button component to app top nav bar that show progress as % of task completion and holds the main part of the code, including progress tracking of the task.
While itâs running you can work with different data and functions.
When itâs loaded it change color to green, show notification and text change to completed. You can push the button and the form will open with the prepared data.
For small data itâs easier just to disable buttons and show notification that will inform you when it is ready. So something similiar to solution proposed by divyeshlakhotia.
You can add to each function short check. If self.task_completed=False then show notification that data is being loaded and the user should wait.
Thatâs a nice solution. Do you put the class into each Form you want to use it in, or could that be used in a Module as well?
I guess this was a simpler issue than I made it out to be. I didnât realize the server calls were indeed blocking code (when I put an alert after the call I saw now that it doesnât run until the server function completes), since components on the forms can still be interacted with, and other parts of the code can still run.
Only the code that immediately follows the call, in the same function. Timers, and usersâ mouse-clicks on buttons, links, etc., can still trigger other client-side functions, and they will run. Therefore, it is the responsibility of application code to disable those things before the server call, if thatâs what it takes.
Trying to get the UI to do what you want sometimes is a never ending job. Tomorrow you may have a new UI element that doesnât play nice with the blocking div, or, as @p.colbertsaid, there may be other reasons why an event is triggered, and you would need to keep using other safeguards.
In cases like this I like to:
Explicitly and visibly disable select UI elements. This is more to give the info to the user that the app is ready or not to perform an action than to affect the appâs behavior.
Use form/global status variables to decide whether to proceed with the execution. Something like if self.loading_data: return.
The first point makes the appâs behavior clear to the user, the second point makes it clear to the developer.
An invisible UI element that affects all, is, yeah, invisible to both user and developer.