0

I have a lightning:input field in which I need to use ternary operator in "value" as shown below but it does not work. I believe I am wrong with the syntax.

<lightning:input name="user" placeholder="Search" value="{!isCreate == 'true' ? !acc.user : !acc.owner}"/>

Where, acc.user and acc.owner has value. acc is iterating variable of List.

2 Answers 2

2

The expression syntax for Aura components is {!...}. When you are inside of the expression (the ... from before), ! is the "not" expression operator. For example, {!!v.isRequired} means "return true if isRequired is false".

Sometimes, people may think that the ! is meant to denote the variable, as in:

`{!v.isRequired && !v.isEmpty}`

The documentation does call this out, but because it's only in one specific part, it's easy to overlook.

0

The below solution actually worked for me. It had extra '!' which caused the problem:

<lightning:input name="user" placeholder="Search" value="{!isCreate == 'true' ? acc.user : acc.owner}"/>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .