Conditional Value Binding


#1

Hi.
I am trying to bind a value from database to a title component. Is there any way to select fields based on condition?

For eg, if TackNo = 100, select Value1, else Value2
Here 100 can be a static value, or it can be yet another field, say Value3.


#2

Yes, just use the expression:

{{TrackNo == 100 ? Value1 : Value2}}


#3

Ternary operator. Cool. :+1:


#4

unable to get this to work:

{{TrackNo == 100 ? Value1 : (Value2;Value3)}}

want to carry out 2 or more actions based on true/false output but this code is not working.

any ideas how to get this to work?


#5

What is the desired result? :slight_smile:


#6

desired result is to get 2 or more actions done (like resetting values of 2 distinct variables) when true or false occur.

with this code {{TrackNo == 100 ? Value1 : (Value2;Value3)}} is run, Value1 and Value2 are set and Value3 is ignored completely.


#7

I still don’t get your idea.
Please tell me what should exactly happen if the trackno is not equal to 100? what do you call actions? Are these values to be returned? Should they be returned at once? I don’t understand you :slight_smile:


#8

exact case:

<dmx-scheduler id="asResendTimer" noload="true" delay="1" dmx-on:tick="(varResendTimer.value > 0 ? varResendTimer.setValue(varResendTimer.value - 1) : (asResendTime.stop();varShowResendLink.value = 1))">

varResendTimer was initialised at a value of 45
am reducing the value of varResendTimer by 1 with each passing second using this scheduler - hence it is like a timer.

now once the varResendTimer value reaches 0, want to stop the scheduler and also reset the value of varShowResendLink to 1.
at this point, the scheduler stops (have verified) but the value of varShowResendLink is not set to 1.

have i explained myself better now?


#9

Yes, that’s what i call a clear explanation :slight_smile:
So please try:

<dmx-scheduler id="asResendTimer" noload="true" delay="1" dmx-on:tick="(varResendTimer.value > 0 ? varResendTimer.setValue(varResendTimer.value - 1) : (asResendTime.stop() + varShowResendLink.setValue(1)))"></dmx-scheduler>


#10

good to know.

and, this solution works like a charm - thanks much @Teodor.

i hope you guys are still looking to improve the ternary operator UI for such complex cases.


#11

Yes we are, still not the highest priority right now.


#12

at least good to know that it will be done.

related note, we see that the timer pauses if tab is not active.

if we switch tabs for some time and then go back to the tab where timer was running, we see that timer had paused and then resumes once tab is active.

this happens on chrome.

on firefox, the timer still runs even when tab is not active.

is there a way to control this via the ActionScheduler of Wappler?


#13

That’s something @patrick can help with :slight_smile:


#14

I remember reading somewhere that the latest chrome tries to be really smart in saving system resources so it “freezes” a tab when you switch away.


#15

Inactive tabs are throttled, intervals and timeouts are throttled to around 1000ms (Chrome and Firefox) and requestAnimationFrame is paused on Chrome when the tab is inactive. I believe the Scheduler uses the requestAnimationFrame.