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
nagendra kumar 21nagendra kumar 21 

I need to unchecked the checkbox if second checkbox is clicked and vice-versa i need to change this on exiting lightning controller

 
Hi Everyone, 

I have a Lightning component and contoller which have 2 group check boxes. 
but now user able to select both checkboxes but we need it to change when a user select one the other one should get unchecked. 
below are the Lightning controler for that. please let me know where to change and should i change anything anything on component also ?
******************
({
    doInit :  function (component,event,helper) {
            var action = component.get("c.initApp");
            action.setCallback(this, function(response) {
                var state = response.getState();
                if (state === "SUCCESS") {
                    component.set('v.pllist4',response.getReturnValue());
                    component.set("v.sobjDetail.Technology__c",true);
                }
                else if (state === "INCOMPLETE") {
                }
                    else if (state === "ERROR") {
                        var errors = response.getError();
                        if (errors) {
                            if (errors[0] && errors[0].message) {
                                console.log("Error message: " + 
                                            errors[0].message);
                            }
                        } else {
                            console.log("Unknown error");
                        }
                    }
            });
            $A.enqueueAction(action);
    },
****************************
 
Deepali KulshresthaDeepali Kulshrestha
Hi Nagendra,

Greeting to you!

I have written a component and controller as per your requirement it contains two checkbox if you click one one checkbox it will show selected checkbox value
and disable the other checkbox and vice-versa.

checkbox.cmp -------------
 
<aura:component >

    
    <div class="slds-box slds-theme_default">
 
    <lightning:input aura:id="checkbox1" type="checkbox" label="checkbox 1" name="checkbox 1" onchange="{!c.handleCheckbox1}"/>
    <lightning:input aura:id="checkbox2" type="checkbox" label="checkbox 2" name="checkbox 2" onchange="{!c.handleCheckbox2}"/>
    </div>
</aura:component>

controller-------------------

({
 handleCheckbox1 : function(c, e, h) {
  c.find('checkbox2').set('v.checked',false); 
     alert( e.getSource().get('v.name'));
 },

    handleCheckbox2 : function(c, e, h) {
  c.find('checkbox1').set('v.checked',false); 
         alert( e.getSource().get('v.name'));
 }
    
})
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
 
nagendra kumar 21nagendra kumar 21
Hello Deepali, i have added your code in controller and Cmp, but i got this below error.

Can you email me once, i will send you my controller and cmp to you. 
nagendra.snowfall@gmail.com

User-added image