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
Radha Rathinavel PandianRadha Rathinavel Pandian 

Show or Hide the button on lightning based on checkbox

Hi,

As I am new to Lightning logic, please help me out for my requirement,

I need to create a lightning button, The button wants to Show / hide depends on my checkbox(legal__c) on my case object.

How can we do this ? 
Raj VakatiRaj Vakati
<aura:component>
    <div class="slds-m-around--large">
        <!--PART 1 for create toggle switch/checkbox form element-->    
        <div class="slds-form-element">
            <label class="slds-checkbox_toggle slds-grid">
                <lightning:input type="checkbox" label="Add pepperoni" name="addPepperoni" checked="true" value="pepperoni"
                                 onchange="{! c.onClick }"/>
                        <lightning:button aura:id="submit" type="submit" label="Submit"  />

            </label>
        </div>
    </div>
</aura:component>
 
({
	onClick : function(component, event, helper) {
        // first get the div element. by using aura:id
      var changeElement = component.find("submit");
        // by using $A.util.toggleClass add-remove slds-hide class
      $A.util.toggleClass(changeElement, "slds-hide");
	  },
})

 
Radha Rathinavel PandianRadha Rathinavel Pandian
Raj,

I have a checkbox on case object withinin salesforce classic.. I just need to check the condition to show the button if my checkbox was unchecked.
VARUN GULATI 30VARUN GULATI 30
Use rendered as below...

<apex:commandButton value="Generate Certificate"
                 oncomplete="onControllerReturn()" onclick="doControllerSave();"
                 rendered="{!IF(Inspection__c.Status__c == 'Pass',true,false)}" />
Nirmal Kumar 91Nirmal Kumar 91
you can put the button inside a div and use toggle class after that:
   <div class="slds-show" aura:id="newButtonDiv">
                <lightning:button   label="New" name="New" title="New"  aura:id="New" onclick="{! c.createNewAction }"/>
                </div>

 var newButton = component.find("newButtonDiv");
        $A.util.toggleClass(newButton, "slds-hide");