I am using a One Shot Button to perform a calculation. There are several input fields, and I want the Calculate button to be enabled or disabled based on the user's input activity.
For example, if a user is entering a value in an input field, the Calculate button should remain disabled until the field loses focus (on blur).
Currently, my logic correctly disables the button while the user is editing a field. However, when I click the Calculate button, the calculation still executes, and the button becomes enabled. This appears to be a race condition between the field's blur event and the button's action execution.
Do you have any suggestions on how to achieve this?
The code was initially implemented in the onActionPerformed event, but it wasn't working as expected. I have now moved the logic to the onClick event. but No luck.
Calculate code is in custom method and I am calling that custom method On "On Click" or onActionPerformed event
I'm experiencing something unusual.
When the browser's Inspect Element window is open, the actionPerformed event does not trigger if the button is disabled.
However, when the Inspect Element window is closed, the event still gets triggered even though the button disabled.
Do you have any idea what might be causing this behavior?
When you click down on the Calculate button, the onBlur event is triggered
By the time you release the click, the custom editing is already back to False and it triggers the onActionPerformed event.
A workaround, although not ideal :
Use the onMouseDown event instead of onActionPerformed.
Make sure to check if the custom editing is in the correct state so that it does not trigger if it is not in the correct state :
if not self.view.custom.editing:
system.perspective.print('execution')
It works on my end but not sure it will work on yours.
If this is not good enough for you, yeah you might need to see that with the support.
The order of events is likely to race, and I would expect onBlur on a field to fire before any event on a separate button. onBlur is simply the wrong event to guard this button. Consider only using onFocus, and setting a view custom property to the name of the most recently focused input field. Then the calculate enable prop can be driven by an expression comparing that custom prop to the appropriate name. No race.
I've just moved the set value into a self.custom.value that the one shot sets and then an on change script on that value executes what you want it to do and then sets itself back to false when done.
Sorta unrelated: I wish the basic button had options for click confirmation, without that we use one shots for almost everything.
Confirmation popups are a UI flaw or "code smell" in my not-so-humble opinion. Anything that needs two-step confirmation should have "mode" for it. A toggle to set the "do something" mode, which enables the "do something" button itself. (Or multiple such.) The mode can be made to expire if unused, end on use, or end when the operator toggles it back off. No races. No popups. Actual actions happen exactly when commanded, not after a popup.
I see where you're coming from for authenticating a critical action but with using perspective on touch tablets it's just nicer having the are you sure? pop up for basic things as a default function of the button.