Expressions with "NOT" criteria in dynamic attributes or conditions not evaluating

Wappler Version : 6.8.0
Operating System : MacOS
Server Model: NodeJS
Database Type: MySQL
Hosting Type: Docker

Expected behavior

What do you think should happen?

When an expression is set to NOT for evaluation in a dynamic attribute or conditional regions, it should evaluate the dynamic expression values correctly.

Actual behavior

What actually happens?

Expressions with NOT are not working. I have included a couple of examples that are and aren't working.

Working with ==:

dmx-show="sc_fetch_tenant_subscription.data.subscriberAccess!='PAID'&&(worksheet_name=='Energy' || worksheet_name=='Water')"

Screenshot showing != code - this is not working.

Not working with !=:

dmx-show="sc_fetch_tenant_subscription.data.subscriberAccess!='PAID'&&(worksheet_name!='Energy' || worksheet_name!='Water')"

Working with contains:

<div id="conditional3" is="dmx-if" dmx-bind:condition="(sc_fetch_tenant_subscription.data.subscriberAccess!='PAID'&amp;&amp;(worksheet_name.contains('Energy') || worksheet_name.contains('Water')))||(sc_fetch_tenant_subscription.data.subscriberAccess=='PAID')">

Not working with !contains:

<div id="conditional3" is="dmx-if" dmx-bind:condition="(sc_fetch_tenant_subscription.data.subscriberAccess!='PAID'&amp;&amp;(!worksheet_name.contains('Energy') || !worksheet_name.contains('Water')))||(sc_fetch_tenant_subscription.data.subscriberAccess=='PAID')">

This works fine in my tests.
Can you please output the different parts of your expression on the page to check what do they return?

<p>subscriberAccess: {{sc_fetch_tenant_subscription.data.subscriberAccess}}</p>
<p>worksheet_name: {{worksheet_name}}</p>

maybe it's just you don't want to use OR for the worksheet_name but AND?

Here's some explanation:

(worksheet_name != 'Energy' || worksheet_name != 'Water')

This condition will always be true because worksheet_name can't be both 'Energy' and 'Water' simultaneously:

If worksheet_name is 'Energy', then worksheet_name != 'Water' will be true.

If worksheet_name is 'Water', then worksheet_name != 'Energy' will be true.

If worksheet_name is neither 'Energy' nor 'Water', then both comparisons are true

So i believe this is where you issue lies.

3 Likes

Hi Teodor,

Thanks for the explanation. I understand where I was going wrong with the use of conditions OR vs AND.

I have tested the conditions with AND and these are working as expected.

Thank you again for a very clear explanation of the issue. I have updated the post from bug to How To in case other users come across this issue when building expressions.

2 Likes