Meteor ignoring 'selected' attribute on <option> on <select multi>

228 Views Asked by At

I am trying to use a multi select box in meteor and have some of the options be marked with selected based on info from the db for use with slectize.js. however it seems like meteor when building its DOM tree ignores the selected property.

<label>User</label>
<select id="customer_user_id" name="user_id" class="form-control input-sm" multiple>
  {{#each users}}
   {{#if inList _id ../customer_user_id}}
     <option value="{{_id}}" selected>{{full_name}}</option>
     {{else}}
     <option value="{{_id}}">{{full_name}}</option>
     {{/if}}
    {{/each}}
</select>

and the helper

Handlebars.registerHelper("inList", function (val, list) {
 console.log(list.indexOf(val) > -1)
 console.log(list)
 console.log(val)
return list.indexOf(val) > -1;

});

i see that the condition is true but there is no options with the selected property

I have been breaking my head on this for more then 24 hours now

I have also tried this method with the same result

<label>User</label>
<select id="customer_user_id" name="user_id" class="form-control input-sm" multiple>
  {{#each users}}
  <option value="{{_id}}" {{selected _id ../customer_user_id "selected"}}>{{full_name}}</option>
  {{/each}}
</select>

with this helper

Handlebars.registerHelper("selected", function (val1, val2, string) {   
 if (val1 === val2) {
    return string;
 }
});
1

There are 1 best solutions below

0
On

Try using selected="selected" instead of just selected:

<option value="{{_id}}" selected="selected">{{full_name}}</option>