This is my sample drop down
<select name="newType" class="parts-select full-width-combo" onchange={{action "loadFilter" value="target.value" }}>
<option value="" selected hidden >Select </option>
{{#each model as |item|}}
<option value="{{item.id}}">{{item.description}}</option>
{{/each}}
</select>
from the relevant template action I wanted to set this selected item dynamically.
As an example it default selected by "Select" and then based on some button click on that page and need to set my selected option to other selected option to be selected. I am not using any plugin and I can't do it here.
I used mut helper to set directly to selectedItemId
property. so onchange it will update it automaticaly. also used ember-truth-helper for eq helper to decide particular item is selected or not.
<select name="newType" class="parts-select full-width-combo" onchange={{action (mut selectedItemId) value="target.value" }}>
<option value="" selected hidden >Select </option>
{{#each model as |item|}}
<option value="{{item.id}}" selected={{if (eq item.id selectedItemId) 'true'}}>{{item.description}}</option>
{{/each}}
</select>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With