Conditional Region Else

I subjected a row to Conditional Region. Visible if inputNumber <= 20
It works perfectly, but I would like an else instruction
if the value greater than 20 display an Alert
It’s possible?

Yeah, add a dynamic event for input updated and trigger the alert if the value is > 20.

The problem is that the input is a hidden field
I really solved by duplicating the Conditional Region and configuring them with alternative data
But I don’t like the solution

Can you share your code?

Please vote!

Schermata 2023-07-04 alle 22.57.23

Conditional regions are rendered server side and not really meant to change their state when a value changes client side. I would add the show if condition to the row instead under dynamic attributes.

I thought they was client side? all the condition regions do to my understanding is make it so what’s inside the conditional region is not rendered in the DOM until the condition is met which is why the app connect one also shouldn’t be used for hiding sensitive data:

If you have sensitive data then you should use conditional regions and best restrict the data server side as well. But conditional regions are evaluated server side on page load.

This probably works better

Schermata 2023-07-04 alle 23.22.34

Show and hide is fine here the only difference between show and hide and the condition region is:

show and hide set the row to display none so it cant be seen visually but is still rendered in the DOM

condition will either render it in the DOM or not meaning you wouldn’t have to load the content inside the condition when the condition is not met for example if you had a table with records it wouldn’t take extra time to process those records

either way it is still in the source but as mentioned your case show and hide should be more than okay :smile:

1 Like

If you really want to hide content even from the DOM, you can try using EJS.
In a Server Action you can do something like:

Condition {{depends_of_your_query}}
THEN
Set Value my_var=1
ELSE
Set Value my_var=0

Now if are you using a server connect in server side data you can easily use EJS, something like this:

<% if (_('my_var==1',locals)) {%>

<div class="row">
<div class="col>
.............
</div>
</div>

<% } %>

I use this a lot, because in nodeJS I found it as the only option. Similar like in PHP using simple conditions.

Nope. They are JS based conditions, evaluated on client side. When a page is requested, you can see all the conditional region HTML data in the network tab.

You need to use server side expressJS bindings <% %> if you wish to restrict sending the HTML to client side… as Alexander has also mentioned.

4 Likes

Yup. A conditional region is just an App Connect component. You can check the code in appconnect.js. It’s the dmx-if component.

1 Like

App Connect doesn’t have block support so it’s the only option available unless you create a custom app connect component.

You’re right. I was wrong here. Thank you for clarifying.

I restrict stuff on the server side and only let conditional regions run on page load or they will error out because of my server restrictions but what I said before was misleading.