0

The official developer specification says the component (API v43) has "values" attribute.

A list of default options that are included in the selected options list box. This list is populated with values from the options attribute.

If I understand this correctly the I should be able to set this attribute with a subset of objects I provide in option list.

Now when I try to set it :

1) The right list of the component is empty
2) The console sends me this greeting

WARNING: "values" must either be a public property of lightningDualListbox or a global HTML attribute

Is this a bug or am I misreading the doc?

3

The Dual List Box with Default Selected options example specified in the docs worked for me:

Component Markup:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes">

    <aura:attribute name="options" type="List" default="[]"/>
    <aura:attribute name="values" type="List" default="[]"/>

        <aura:handler name="init" value="{!this}" action="{!c.init}"/>

        <lightning:dualListbox name="multipleOptions"  
                               label= "Select Options" 
                               sourceLabel="Available" 
                               selectedLabel="Selected" 
                               options="{!v.options}" 
                               value="{!v.values}" 
                               onchange="{! c.handleChange }"/>

    </aura:component>

Controller JS:

({
    init: function (cmp) {
        var items = [];
        for (var i = 0; i < 15; i++) {
            var item = {
                "label": "Option " + i,
                "value": "opt" + i,
            };
            items.push(item);
        }
        cmp.set("v.options", items);
        // "values" must be a subset of values from "options"
        cmp.set("v.values", ["opt10", "opt5", "opt7"]);
    },

    handleChange: function (cmp, event) {
        // This will contain an array of the "value" attribute of the selected options
        var selectedOptionValue = event.getParam("value");
        alert("Option selected with value: '" + selectedOptionValue.toString() + "'");
    }
})

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.