0
votes

How can I check in Ember if ember-power-select has a value/something is selected?

Edit: I already have the onchange=(action (mut selection)). But I have a computed property, which listen on 'selection'. When I visit the site for the first time(url or reload) then the selection will be filled based on model.name. The value is shown up in power select, but the computed property doesnt get called

1
selection will be filled based on model.name - where are you setting this to happen ? include that code pleaseEmber Freak
hey, I made an mistake. The computed property only listen on 'selection', but I have to hear on 'selection.name' because it is a modelBenny Alex

1 Answers

1
votes

Go through awesome doc http://www.ember-power-select.com/docs/action-handling . Actually its following DataDownActionsUp principle, chnages will be communicated through actions.

You need to define onchange action

{{#power-select
  selected=destination
  options=cities
  onchange=(action "chooseDestination")
  as |name|
}}
  {{name}}
{{/power-select}}

Implement the logic in corresponding place,

import Ember from 'ember';
export default Ember.Controller.extend({
  cities: ['Barcelona', 'London', 'New York', 'Porto'],
  destination: 'London',

  actions: {
    chooseDestination(city) {
      this.set('destination', city);
      // this.calculateRoute();
      // this.updatePrice();
    }
  }
});

If you just want to update selected property alone, then you can simply say onchange=(action (mut destination))