ember.js icon indicating copy to clipboard operation
ember.js copied to clipboard

Select component is a nightmare (just a idea)

Open mxrguspxrt opened this issue 11 years ago • 7 comments

  1. Sourcecode is ugly and ununderstandably complicated
  2. Component itself is complicated with a lot of parameters (content, selection, labelpathwhat?)
  3. 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.

mxrguspxrt avatar Sep 28 '15 10:09 mxrguspxrt

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.

rwjblue avatar Sep 28 '15 15:09 rwjblue

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 avatar Sep 28 '15 18:09 stefanpenner

@stefanpenner Thank you! You are awesome.

mxrguspxrt avatar Sep 28 '15 18:09 mxrguspxrt

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.

7sedam7 avatar Nov 05 '15 11:11 7sedam7

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.

mxrguspxrt avatar Nov 05 '15 12:11 mxrguspxrt

thanks @mxrguspxrt, but I really wanted to use this mul thing :D

7sedam7 avatar Nov 05 '15 12:11 7sedam7

Try "mut" thing instead of "mul" thing and make sure that your Ember version supports it. :)

mxrguspxrt avatar Nov 05 '15 12:11 mxrguspxrt