1

I am getting the below error for the lightning:dualListbox but not for the lightning:select in the below component code. The component is being dynamically created. Other dynamically created lightning:input components also don't hit this error.

{"status":"ERROR","message":"Assertion Failed!: \"onchange\" must either be a public property of lightningDualListbox or a global HTML attribute : false"}

<aura:attribute name="onchange" type="Aura.Action"/>

<aura:if isTrue="{! !v.multi }">
    <lightning:select
            name="{! v.name }"
            label="{! v.label }"
            value="{! v.value }"
            class="{! v.class }"
            onchange="{! v.onchange }"
            >
        <aura:iteration var="option" items="{!v.options}">
            <option value="{! option.value }">{! option.label }</option>
        </aura:iteration>
    </lightning:select>
</aura:if>
<aura:if isTrue="{! v.multi }">
    <div class="{! v.class }">
        <lightning:dualListbox
                name="{! v.name }"
                label="{! v.label }"
                value="{! v.value }"
                onchange="{! v.onchange }"
                options="{! v.options }"
                />
    </div>
</aura:if>

The onchange attribute value is:

var onchange = component.getReference('c.onFieldChange');

where component is the containing component for this and other dynamically created components.

Any suggestions for what a global HTML attribute is in this context? Or a way to get this code to work?

2

Luckily after a few failures I think I have a workaround making use of the answer to Calling Aura.Action attribute from Lightning Controller/Helper.

Only for the lightning:dualListbox, I've added a local controller method that then calls the external method and this seems to work:

<aura:attribute name="onchange" type="Aura.Action"/>

<lightning:dualListbox
    onchange="{! c.localOnchange }"

Controller:

localOnchange  : function(component, event, helper) {
    $A.enqueueAction(component.get("v.onchange"));
},
|improve this answer|||||

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.