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
TechEd_ProgrammerTechEd_Programmer 

Set a boolean value in a component

I have a flag in my Aura:if that allows me to add columns to my interface. I am able to access the controller, however, it does not appear to be updating the flag.

Component Code:
<aura:if isTrue="{!(not(v.showYear4))}">
                    	<lightning:buttonIcon name="4" iconName="utility:add" title="Add Year 4" onclick="{!c.addColumn}" />
                    </aura:if>
                </th>
                <aura:if isTrue="{!v.showYear4}">
                    <th scope="col">
                        <span class="slds-truncate" title="YR4">Year 4</span>
                    </th>
                </aura:if>
Controller Code:
addColumn : function(component, event, helper){
    	
        console.log("made it here");
        var currentTarget = event.currentTarget;
        var currentYear = currentTarget.getAttribute("name");
        component.set("v.showYear"+currentYear,true);
        console.log("v.showYear"+currentYear);
        
    }

Any help wouldd be appreciated. The code is not displaying the second console.log statement but is displaying "made it here"


 
Best Answer chosen by TechEd_Programmer
David Zhu 🔥David Zhu 🔥
I found another simpler way,just need to change code in JS controller:
addColumn : function(component, event, helper){
    	
        console.log("made it here");
        var currentYear = event.getSource().get("v.name")
        component.set("v.showYear"+currentYear,true);
        console.log("v.showYear"+currentYear);
        
    }


 

All Answers

Agustin BAgustin B
Hi, verify what you are receiving in the current target and the currentYear, something if breaking the code, thats why you dont see the last log.
Put a log for current Target and for current Year to see if that is working properly.

If it helps you please mark this as correct, it may help others.
David Zhu 🔥David Zhu 🔥
You may need to change the code a bit.
in HTML
<lightning:buttonIcon name="4" iconName="utility:add" title="Add Year 4" onclick="{!c.addColumn}"  aura:id="button4"/>

In Js controller
addColumn : function(component, event, helper){
    	
        console.log("made it here");
        var currentTarget = event.currentTarget;
        var currentYear = currentTarget.getAttribute("name");
        var currentYear = component.find("button4").get("v.name");
        component.set("v.showYear"+currentYear,true);
        console.log("v.showYear"+currentYear);
        
    }


 
David Zhu 🔥David Zhu 🔥
I found another simpler way,just need to change code in JS controller:
addColumn : function(component, event, helper){
    	
        console.log("made it here");
        var currentYear = event.getSource().get("v.name")
        component.set("v.showYear"+currentYear,true);
        console.log("v.showYear"+currentYear);
        
    }


 
This was selected as the best answer
TechEd_ProgrammerTechEd_Programmer
Thank you David! That did it.