0

I am trying to dynamically create a checkbox component and then store its value in a record's field. I have a standard checkbox component that works. I can't figure out how to dynamically create the same component & store the value of the checkbox. I think my problem is related to the onCheck call. I have onCheck in the controller of the component that is creating the dynamic checklist. I can't seem to get to onCheck. I am not sure if my syntax is create for trying to call onCheck dynamically. Do I need to dynamically create onCheck, etc.?

                $A.createComponent(
                "ui:inputCheckbox",
                { 
                    "change" : "{!c.onCheck}",
                    "value" : component.getReference("v.EventRSVP."+ fieldAPIName),
                    "aura:id": "findableAuraId",
                    "label": fieldLabel
                },

Here is the component and controller that I have that work - not being created dynamically. Component

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes">
<aura:attribute name="myBool" type="Boolean" default="false"/>
<ui:inputCheckbox aura:id="checkbox" label="Select?"  change="{!c.onCheck}"/>
<p>Selected:</p>
<p><ui:outputText class="result" aura:id="checkResult" value="false" /></p>
<p>The following checkbox uses a component attribute to bind its value.</p>
<ui:outputCheckbox aura:id="output" value="{!v.myBool}"/>

Controller

({
onCheck: function(cmp, evt) {
    var checkCmp = cmp.find("checkbox");
    var resultCmp = cmp.find("checkResult");
    resultCmp.set("v.value", ""+checkCmp.get("v.value"));
    cmp.set("v.myBool", checkCmp.get("v.value"));
}

})

0

I just figured out my problem. I needed the line in the dynamically created component to call onCheck by using the following code instead of what I had:

                        "change" : component.getReference("{!c.onCheck}"),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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