Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polymer option selected

How do I set select option selected in Polymer 1.0?

<select id="typeSelect" style="width:100%;" value="{{item.type::change}}">
  <option value="">Choose a type</option>
  <template is="dom-repeat" items="{{types}}" as="type" >
    <option selected?="{{type==item.type}}">{{type}}</option>
  </template>
</select>
like image 344
user913129 Avatar asked Mar 14 '23 23:03

user913129


1 Answers

You were very close. Use this.

<select id="typeSelect" style="width:100%;" value="{{item.type::change}}">
  <option value="">Choose a type</option>
  <template is="dom-repeat" items="{{types}}" as="type" >
    <option selected$="{{selected(type,"yourtypetocompare")}}">{{type}}</option>
  </template>
</select>

Now, add a function in your polymer's element.

  selected: function(item, type){
    return type == item.type;
  },
like image 157
Flavio Ochoa Avatar answered Mar 29 '23 06:03

Flavio Ochoa