WIP: condition != is getting true if value is 0

I use a condition with != to show or hide a div with content in it based on the field is emtpy or not.
The problem: If the field value is zero the condition also becomes true.

Since zero does not automatically mean empty, this will be a bug in the worst case.
The ACF field is a textfield which also means that normaly shouldn’t happen. :slight_smile:

The version here is still 1.9.7 (Jenn had made changes to this instance in the Brickscore which I don’t think have yet reached the final version).

Hi @sebastianberger ,

Do you mean this ACF field might consist only “0”? And sometimes it could be some other text like “hello” or totally empty.
Can we have some use cases so we can discuss how to handle this?
Of course for the time being, strlen with {echo:} could be the easiest solution.

Regards,
Jenn

1 Like

Hey Jenn! :slight_smile:

Thanks for your answer!

The field that is proved for the condition can contain a number from 0 to 100. It’s a textfield.
One condition proves simply is field not empty (!=)-> show the div. Why ever if the fieldvalue is 0 the zero gets interpreted as empty (whats not true, especially not for a textfield) and the div with the parts are hidden.

My usecase is (you know the project :wink: ) on testsiegertarife.de the insurance feature cards. If a acf field doesn’t contain a value the rating bar with value etc. should be hidden.

Does this makes sense? :slight_smile:

1 Like

!=
Don’t show if empty, null or false - numeric or boolean field
!=“”
don’t show if empty - string field

3 Likes

As written. It’s a textfield so 0 should be a string and no “false” value.

You do you my friend, but there’s a reason testing for empty strings is done with !=“” and not !=
If you want to tell the PHP devs to do it differently, I wish you luck:

2 Likes

Hi @sebastianberger

Thanks for the use case example. Currently discussing with team.

For your case, I will use DD >= 0 to render the element ( Show this element if dynamic tag value is equal to zero or higher)

However, it’s not working in Bricks now because we have a logic to convert 0 to a boolean false.

@digismith Appreciate your help. But this is a valid problem if the user wants to show an element as long as a value not empty includes “0” value.

Will update this as soon as we have a solution.

Regards,
Jenn

1 Like