Nam Nam - 2 months ago 8x
Javascript Question

ember-cli How to set default value from form select?

My template:

<select name="lang" id="lang" onchange={{action "selectOption" value="target.value"}}>
<option value="">--Choose--</option>
{{#each model as |lang|}}
<option value="{{lang.url}}">{{lang.title}}</option>

has one of the values:
['php', 'javascript', ...]

My Controller:

lang: 'php', //this is not working, I am thinking of something like lang.url or lang.get('url') but looks like it is still not right ..
actions: {
selectOption: function(option) {
this.set("lang", option);

How can I set the default value of select to php?


Set true to the selected option's selected attribute. Something this:

<option value="{{lang.url}}" selected={{eq lang.url 'php'}}>{{lang.title}}</option>

eq helper can be found here.