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

@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.

  • 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 Jul 6 '18 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.

  • +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 Jul 6 '18 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 Jul 8 '18 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.