Benny Alex
Benny Alex

Reputation: 156

Ember-Power-Select: Check if something is selected?

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

Upvotes: 0

Views: 431

Answers (1)

Ember Freak
Ember Freak

Reputation: 12872

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))

Upvotes: 1

Related Questions