This is probably a very simple question and I'm just overlooking a very simple solution. I am trying to write values from a selectedRow in a table to a text field. If the value in the row is null or blank, I want to write N/A, but it it is not null or blank, I want to write the value. Can someone tell me how I would go about doing that?
Hi Tomm,
You can check for Falsy values with ||.
For instance
{{ tableName.selectedRow.name || "N/A" }}
would check if name is null or blank and if it is, it will use "N/A". Hope that helps.
Unfortunately, this did not work.
I am using the following code in a text field:
{{ table4.selectedRow.email ? 'N/A' : table4.selected?Row.email }}
I'm not sure what would need to go before the ? to make the statement work. I hope that makes sense.
Hi tomm,
You're getting close. What your statement (called a ternary is doing is "check if selectedRow.email exists, if it does, use "N/A" otherwise use selectedRow.email. So you just need to switch the second and third elements. Also it looks like you might be trying to do optional chaining but you need question mark period, so ?.
So easiest might be
{{ table4?.selectedRow?.email || "N/A" }}
or could do
{{ table4?.selectedRow?.email ? table4.selectedRow.email : "N/A" }}
Thanks @julius_jet. I had actually just figured that out and when I came back to post that I had the solution, your reply was here. Your second option is what suddenly dawned on me. Thanks again.