function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Akshay MenseAkshay Mense 

Multi Select checkbox

Hello I am currently working on one of the requirement which requires use of multiselect checkbox. 

for e.g 
If yes, Which University?
1) Pune - checkbox field
2) Delhi - checkbox field

Other - text box field
ANUTEJANUTEJ (Salesforce Developers) 
Hi Akshay,

>> https://salesforce.stackexchange.com/questions/240059/how-to-display-hide-fields-in-lightning-component-using-javascript

I see that the above link has a similar implementation that you can try checking out.

Below is the selected best answer so quick reference:
 
While you can certainly show and hide fields using JavaScript, it's usually more idiomatic in Lightning to allow the framework to handle conditional rendering using <aura:if> expressions built around the values of your attributes.

Here's a quick example of how to show and hide fields idiomatically in a Lightning component. This is an abbreviated example that's meant to show the structure, not a working component! I'd encourage adapting this type of structure to your specific needs.


<aura:component>
    <aura:attribute name="industry" type="String" default="Education" />
    <aura:attribute name="otherIndustry" type="String" />

    <lightning:select name="select1" label="What industry?" value="{! v.industry }">
        <option value="Education">Education</option>
        <option value="Finance">Financial Services</option>
        <option value="Sports">Sports and Recreation</option>
        <option value="Other">Other</option>
    </lightning:select>

    <aura:if isTrue="{! v.industry == 'Other' }">
        <lightning:input label="Other Industry" value="{! v.otherIndustry }" />
    </aura:if>
</aura:component>



What we do here is establish an attribute, industry, to hold the value of the <lightning:select> component, bound via its value attribute.

Then, we wrap another <lightning:input>, which we want to show conditionally, in an <aura:if> component. The <aura:if> includes a bound expression referring to the same attribute to which the select's value is bound. The framework then ensures that updates to these values are recalculated in all of the bound locations and rerenders elements appropriately.

Upshot? If you run this component, you'll find that when you select "Other", the "Other Industry" field appears immediately, no JavaScript client code required, and disappears again when you choose any other option. Let the framework do the work for you.

You can apply exactly the same pattern to your problem.

Further Reading
aura:if
Lightning Component Basics: Attributes and Expressions, which includes more on these topics.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.