Skip to main content
I'm attempting a trailhead challenge, and completely stuck when working with ui:inputCheckbox.

I can't find in the documentation how I can:

a) determine if the checkbox is checked

b) change it from unchecked to checked (or vice versa).

 
4 respostas
  1. 16 de jun. de 2016, 20:17
    Hi Andrew,

    Please take a look at my example. You should be able to fix your issue based off this code.

    My component:

    <aura:component >

    <aura:attribute name="item" type="Camping_Item__c" required="true"/>

    <ui:button label="Packed!" press="{!c.packItem}"/>

    <ui:outputText value="{!v.item.Name}"/>

    <ui:outputNumber value="{!v.item.Quantity__c}"/>

    <ui:outputCurrency value="{!v.item.Price__c }"/>

    <ui:outputCheckbox value="{!v.item.Packed__c}"/>

    </aura:component>

    As you can see, the attribute is referenced as "item". 

    In your controller, you will first need to get a reference to "item" and then check the field values. In this case, I set the value to true and update the ui:

    //Get item (Camping_Item__c record)

    var cmpItem = component.get("v.item", true);

    //Set the checkbox to checked

    cmpItem.Packed__c = true;

    //Update the ui

    component.set("v.item", cmpItem);

    Hope this helps!

    Happy coding! :-)

    Best regards,

    Martijn Schwärzer