Skip to content

Question - select default option in the selectbox #2

@githubGabriela

Description

@githubGabriela

How do you select a default option in the select box?
Let's say you use this select box inside a form and when you want to edit the form the value Antarctica must appear already selected in the select box.

One possible solution would be this:
// set value
$("#my_select2_element").select2("val", "Antarctica");

This solution works with a select box static e.g.:

Asia Antarctica

but will not work if the options are created inside a template dom-repeat because every option is inside a template.

Another solution will be this:

{{item.label}}

but this will select a value inside the select list options. Still, there will be no value preselected in the select box.

How would you preselect a value in the select box?

Thankx!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions