0

I need to display a dropdown in a lightning component, but I also want the user to be able to add items to it. So far I'm not seeing this ability in either the ui:inputSelect or the lightning:select. Any advice?

closed as off-topic by Eric, Lance Shi, Tushar Sharma, Mohith Shrivastava, Dave Humm Dec 23 '16 at 9:24

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" – Eric, Lance Shi, Tushar Sharma, Mohith Shrivastava, Dave Humm
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Please visit - How to Ask and narrow your question as well as include what you have tried so far – Eric Dec 22 '16 at 23:00
1

You can use ui:inputSelect and set the options attribute. When this attribute is set, the input will automatically update the list with the new options.

You can see an example here under the "Generating Options Dynamically" section. In this example they set the options attribute in the init handler like so:

({
    doInit : function(cmp) {
        var opts = [
            { class: "optionClass", label: "Option1", value: "opt1", selected: "true" },
            { class: "optionClass", label: "Option2", value: "opt2" },
            { class: "optionClass", label: "Option3", value: "opt3" }

        ];
        cmp.find("InputSelectDynamic").set("v.options", opts);
    }
})

For your case, instead of setting options in the init handler you can get, modify, and re-set the options attribute based on user input.

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