1

I would like to hide a form field in a Lightning component. I am trying to do something like the following but the visibility attribute isn't being recognized.

 lightning:select aura:id="leadtier" label="Interested Membership Tier: " required="false" visibility="hidden" value="{!v.InterestedMT}" name="interestedMembershipTier"

2 Answers 2

2

@Michele-Kleinhomer - If you are trying to hide the field on the form so that you can use the value of that field in your logic, you can specifying the class attribute and set it to slds-hide. Let me know if this works.

1
  • Your information is helpful, but do add few more details for a more meaningful answer (I have learned it in this forum). Address the issue and then recommendations with relevant references and examples.
    – Jayant Das
    Commented Jul 6, 2018 at 22:13
1

As for your issue:

but the visibility attribute isn't being recognized

It's because visibility is not a valid attribute for lightning:select. You can refer to what are available attributes for this component on its documentation here.

There are couple of ways to hide particular elements on your component, and you can use aura:if as one of those. You can find more on aura:if on its documentation here.

Also refer to the page Dynamically Showing or Hiding Markup for more details.

2
  • +1 but I'd prefer slds-hide over aura:if in practical cases; the overhead of rendering can be quite expensive if you're toggling DOM elements all the time.
    – sfdcfox
    Commented Jul 6, 2018 at 21:56
  • True, and one of the reasons I started the answer with "couple of ways", as it totally depends on the use case :). aura:if is I would say more preferable if you want to reduce the load time, and when you know your conditions will match a certain criteria and it's not too dynamic for a change so that there's a less chance of creating/destroying the contents. Again the best design is totally use case dependent.
    – Jayant Das
    Commented Jul 8, 2018 at 3:27

You must log in to answer this question.

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