I have inputCheckbox which is on the Lightning tab.

On click of button, I'm trying to set the value of checkbox to true. It seems inputCheckbox is not rendering properly. When I click on button first time I'm getting the value of component.find("inputCheck") undefined but when I click the second time I'm getting the value. Sometimes this number of click increases to 4 to 5 times.


        <lightning:tab id="tab1">
            <ui:inputCheckbox aura:id="inputCheck"/>
                <button id="saveButton" onclick="{!c.ButtonClicked}">Save</button>


 ButtonClicked : function(component,event,helper){

        component.find("inputCheck").set("v.value", true); 

closed as off-topic by glls, Basti, Raul, battery.cord, Samuel Dare Dec 18 '17 at 16:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – glls, Basti, Raul, battery.cord, Samuel Dare
If this question can be reworded to fit the rules in the help center, please edit the question.

  • voting to close as the question has not been updated with a reproduceable code sample – glls Dec 18 '17 at 0:46

using the "lightning:input" component, You can set the value by using ("v.checked", true) instead of "v.value"

as for the ui:inputCheckbox, "v.value" should work. I tested in my community with your exact same code, and the checkbox is set to true when clicking the button.

if you have other functions or code interacting with your component, you might want to share it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.