Hide element based on json field won't work if json/node isn't found

Hi all. I want to hide an element based on a field that is json formated. The same field can return two diferent json structures I am checking for the existence of a specific node like {{!orders.data.id}} in the hide parameter of the button I wan't to hide. The problem is that when the field is empty or is filled with the second json option (that dont have a .id node) the hide check returns an error and doest hide the button. How can I handle this?

Thank you.

Can you handle it inline? Something like

{{(orders.data.id == null) ? "this" : "or that"}}

Hi @minijohn

I was trying your suggestion and now I think I better understand what is happening. When there is a json and it can't find the node, it works fine. Problem is when the field is empty, then the test fails. I will use your suggestion to handle it inline, first testing if the json exists and only then testing if a specific node exists inside this json.

Thank you!

:metal: Awesome, One down :))

1 Like

Hey @igoraguiar! As an addon to @minijohn 's suggestion, you can use the optional chaining operator to shorten the logic a bit! In this example, data.bad is undefined:


Awesome @alex-w
I didn't know that operator!
Tks

1 Like