Select component is a nightmare (just a idea)
- Sourcecode is ugly and ununderstandably complicated
- Component itself is complicated with a lot of parameters (content, selection, labelpathwhat?)
- Component is unusable if you want to use helpers in label or value (for example when you need translations)
How usage should be:
= select-component selected=model.bestBook placeholder=(t 'Please select the best book')
each books as |book|
option value=book
= (t book.title)
With this approach code for select-component and option-component is only few lines also the usage woud be much more dynamic compared to existing solution.
select-component.js
import Ember.Component from 'ember';
export default Ember.Component.extend({
selected: null,
changed: function(event) {
this.set('selected', event.target.value);
},
init: function() {
this._super(...arguments);
this.on('change', this, this.changed);
}
});
select-component.emblem
select prompt=placeholder
Say that you want it and I will create PR.
I do not understand your examples (haven't really done any Emblem templates before), but I completely agree that Ember.Select was absolutely horrible. For that reason it was deprecated in 1.13 and removed in 2.x.
As @rwjblue the select helper in core has been deprecated in-favor of the following 2 approaches:
- using HTML/HTMLBars directly:
<select onchange={{action (mut value) value="target.value"}}>
{{#each choices as |choice|}}
<option value={{choice}} selected={{is-equal value choice}}>{{choice}}</option>
{{/each}}
</select>
- Or using more special purpose select add-ons (typically attempting to make 1 or 2 specific scenarios more ergonomic) -> http://www.emberaddons.com/?query=select
In light of the above, I am closing this. If we have misunderstood, please provide clarification, and we can explore further.
@stefanpenner Thank you! You are awesome.
Can someone please help me with how to write this example in emblem.
Things I have tried:
select onchange={action (mul value) value='target.value'}
select onchange={mul value value='target.valeu'}
select onchange={mul value target.valeu}
select onchange={mul value}
I can not get it to work. I don't get an error. The last example is the only one that actually showed the options (for other examples there was an empty select), but the value did not get updated.
I am using plain HTML without SELECT tag, but I think that onselect=(action 'selectChanged') and then selectChange receives function selectChanged(event) and event.target.value.
thanks @mxrguspxrt, but I really wanted to use this mul thing :D
Try "mut" thing instead of "mul" thing and make sure that your Ember version supports it. :)