Simple question but breaking my head over it.
I have a page that toggles a bit to view a value. Basically changes the visibility on a label when I click a button. How could I have it change this value back from true to false after 10 mins. Hoping that makes sense
On the view's CUSTOM properties create an object as shown:
- On
setTime
create an expression binding now(0)
. This will fire once when the application loads.
- On
visibility
create an expression binding,
!(now(1000) - {view.custom.visibilityTimer.setTime} > 10000)
(Note the !
at the start.) This will turn false
when more than 10 s has passed since the time was set.
- On the button create an
onActionPerformed
event script:
def runAction(self, event):
self.view.custom.visibilityTimer.setTime = system.date.now()
This will write the time of button press into the setTime
property.
Improvements
- You could also bind the button's enabled property to the
visibility
property to prevent a second press while it's timing out, if desired.
- Make a session variable to hold the time delay value and reference that in the visibiliy binding. That way you can change the delay for everywhere you use it in one place without editing expressions.
Just watch the label to see if it shows up for 10 s when the view is first loaded. You might not want that.
4 Likes
oh wow thank you this is exactly what I need. Thank you very much