Conditional Value Binding

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.

Yes, just use the expression:

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

1 Like

Ternary operator. Cool. :+1:

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?

What is the desired result? :slight_smile:

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.

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:

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?

1 Like

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>

2 Likes

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.

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

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?

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

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.

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.

1 Like

Trying to implement this logic with a conditional based on cookie
I set a cookie with two possible values.
If cookie value ==‘Yes’ I want to dmx-bind:value=“a value”
If cookie value ==‘No’ I want to dmx-bind:value =“another value”

Trying with no success. Any help much appreciated
Thank you!

Hey Niko,
What exactly are you trying? What’s your code?

This is the actual code. Know it is wrong but this how it currently is
<input type="text" name="orderAmount" id="orderAmountgr" dmx-bind:value="(cookies1.data.currency=='EUR' ? setValue(orderAmountPreviewgr.value) :(api_get_rates.data.rates.EUR*orderAmountPreviewgr.value).formatCurrency(' ', '.', ',', '2')">

What is that thing you are trying to setvalue to? Is it the orderAmount input itself?
Also - where is the: orderAmountPreviewgr.value coming from - what is it?

Can you explain more detailed please?

Wait let me upload it. brb in a min