machty / emblem.js

Emblem.js - Ember-friendly, indented syntax alternative for Handlebars.js
http://emblemjs.com
MIT License
1.04k stars 81 forks source link

How do I make a select for a belongsTo relationship? #268

Closed NullVoxPopuli closed 8 years ago

NullVoxPopuli commented 8 years ago

so far I have this:

      select change='selectOption' value=model.membershipOption
        option value='' Select Membership
        each membershipOptions as |option|
          option value=option.id 
            = option.name

selectOption is properly triggered, but the parameter is empty.

I'm wanting to set the membershipOption relationship on the model.

NullVoxPopuli commented 8 years ago

I decided to go with ember cli x select, and came up with this:

      = x-select value=model.membershipOption
        option value='' Select an option
        each membershipOptions as |option|
          = x-option value=option
            = option.name
gregmalcolm commented 8 years ago

Me too.

I'm struggling with make Ember2 select work in emblem too. I'm trying to following this pattern:

<select onchange={{action (mut vehicle) value="target.value"}}>
  {{#each vehicles as |vehicleChoice|}}
    <option value={{vehicleChoice}} selected={{eq vehicle vehicleChoice}}>{{vehicleChoice}}</option>
  {{/each}}
</select>

source: http://balinterdi.com/2015/08/29/how-to-do-a-select-dropdown-in-ember-20.html

... but I can't make it translate to emblem though the change event or through {action}.

thec0keman commented 8 years ago

Would the following work?

select{ action (mut vehicle) value='target.value' on='change' }
  = each vehicles as |vehicleChoice|
    option value=vehicleChoice selected={ eq vehicle vehicleChoice }
      = vehicleChoice

This translates to

<select {{action (mut vehicle) value="target.value" on='change' }}>
  {{#each vehicles as |vehicleChoice|}}
    <option value={{vehicleChoice}} selected={{eq vehicle vehicleChoice}}>
      {{vehicleChoice}}
    </option>
  {{/each}}
</select>

Emblem really needs better support of action helpers on HTML elements. It's been something I've been meaning to poke at for awhile.

gregmalcolm commented 8 years ago

I tried some variations of that yesterday but I was seeing errors if I didn't put (mut vehicle) in quotes. Which of course would do me no good.

thec0keman commented 8 years ago

270 should fix this.

thec0keman commented 8 years ago

Fixed by #270