I have a lightning:select
picklist on a Lightning component called "Best Method of Contact" which is a required picklist, but the required picklist defaults to a blank 'placeholder' value that the user must change. The values are as follows:
- -SELECT ONE- (Default/Undefined)
- Phone
Issue: I also want to present the user with a
lightning:input
to enter
either a Phone Number, or an Email, and I want this rendered
dynamically onChange of the picklist so that if the user chooses
"Email" they get the Email input, and the Phone input for Phone.However, when the user hasn't selected either option yet, and is still
set to the default -SELECT ONE- option, I don't want to render EITHER
of thelightning:input
fields on the page.
I know aura:if
is the lightning equivalent of If X, Do Y, ELSE do Z
but it doesn't appear to have an ELSE IF condition in the documentation, so it really is only a boolean as far as I can tell. If the condition is met, render A, otherwise render B.
This doesn't work in my case because I have 3 conditions not 2, A (Phone), B (Email), and C (None).
Question: I imagine I can wrap an
aura:if
around anotheraura:if
to use it
very similarly to an IF statement in a Formula field, but before I
went down that route I wanted to make sure I wasn't missing any other
(better or more reliable) option that I might be able to use for this.
Lightning:input
doesn't have arendered
variable like the
apex:outputPanel
component does, so I can't set it there, and I
can't find an equivalent to the rendered variable on thelightning:
componentsIs there a more correct way to do this?
Best Answer
I would think the simplest way to achieve is to just write 3 different
aura:if
blocks. Something as below?