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
SHAIK MOULALI369SHAIK MOULALI369 

lightning button executed only 2 times

While clickiing lightning button (Toggle), it has woring only 2 times and after not executing properly.

Component Code : 
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="buttonLabel" type="String" default="Search Button"/>
    <aura:attribute name="newLabel" type="String" default="New Button"/>
    <aura:attribute name="isNewAvailable" type="Boolean" default="false"/>
    
    <aura:attribute name="CarTypes" type="String[]" default="All Types,Sport Car,Luxury Car,Van"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <lightning:layout horizontalAlign="center">
        <lightning:layoutItem padding="around-medium">
            <lightning:select name="selectItem " aura:id="CarType" label="All Types" variant="label-hidden" > 
                <option value="" text="All Types"/>
                <aura:iteration items="{!v.CarTypes}" var="CarType">
                    <option value="{!CarType}" text="{!CarType}"/>
                </aura:iteration>
    </lightning:select>
        
            <lightning:button label="{!v.buttonLabel}" onclick="{!c.onSearchClick}" variant="brand"/>
            <lightning:button variant='neutral' label="Toggle Button" onclick="{!c.toggleButton}" />
            <aura:if isTrue="{!v.isNewAvailable}">    
                <lightning:button variant='neutral' label="{#v.newLabel}"/>
                <aura:set attribute="else">
                    New button cannot be added here
                </aura:set>    
            </aura:if>  
            
        </lightning:layoutItem>
    </lightning:layout>
</aura:component>
Controller Code : 
({
    onSearchClick : function(component, event, helper) {
        helper.handlerOnSeearchClick(component, event, helper)
    },
    
    toggleButton : function(component, event, helper) {
        var CurrentValue = component.get("v.isNewAvailable");
        console.log('Method is exicuted');
        if(CurrentValue){
            console.log('New value--1'+CurrentValue);
          component.set("v.isNewAvailable","false");
            
        }    
        else{
             console.log('New value--2'+CurrentValue);
            component.set("v.isNewAvailable","true");
           
        }  
    },
    doInit : function(component, event, helper) {
        
        var CarTypes = component.set("v.CarTypes");
        component.set("v.CarTypes", ['Sport Car','Luxury Car','Van']);
        
    }
    
})
Helper Code : 
({
    handlerOnSeearchClick : function(component, event, helper) {
        alert('Search Button was clicked');
    }
})

this is my complete code, Kindly suggest how to resolve this type of Issues.
Below is the O/P of my my code.
O/P of Toggle button aftr clicking 5 times
ANUTEJANUTEJ (Salesforce Developers) 
Hi Shaik,

I see that the method is being called and what is the scenario you are trying or where are you seeing the issue?

Also, is this a trailhead question? or an implementation issue?

thanks.
SHAIK MOULALI369SHAIK MOULALI369
Hi Anutej,

this is not a trailhead quation, it was implementing my own app.

I am trying to implement a toggle button, Initially it was "New button cannot be added here",
Click 1 : When clicking toggle button i need to get "New Button",
Click 2 : again clicking toggle button again i get  "New button cannot be added here"
Click 3 : When clicking toggle button i need to get "New Button",
Click 4 : again clicking toggle button again i get  "New button cannot be added here"
Like wise.... but the above code only 2 clicks has working... remaining not working...

Kinldy suggest how to resolve this.
 
Karim LaphroaigKarim Laphroaig
As an overweight person looking to get more active, I found this article https://www.bikehacks.com/bikes-for-heavy-people/ to be incredibly informative. The author provides a lot of helpful tips on how to choose the right bike, including information on weight limits and different types of frames. The article is well-written and easy to understand, and I appreciated the author's attention to detail. If you're looking for a bike that will help you get moving, this article is definitely worth a read.