Skip to content

Select optgroup in multi select using js #3708

@iamawebgeek

Description

@iamawebgeek

I have an input with optgroups and multiple turned on. I need to select an parent option (optgroup) using js. I tried to do:

$("#select2").select2("val", $("#select2").data("select2").opts.data[0]); // I got no reaction
$("#select2").select2("val", ["2","3","7"]); // pass all the child ids in array, but it selects all children options

I googled a lot, but didnt found any useful suggestions. My select2 version is: 3.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions