Abdulelah
Abdulelah

Reputation: 691

Using select2 addon with Ember cli

I'm kind of new to Emberjs and I'm having trouble using select2 addon.

The docs were completely useless, I couldn't get a single info from there. Now I want to make the user to be able to select multiple data gathered from the database I tried using "model" in the "content" section but it's not working.

Here is the sample I took from the docs

{{select-2
  content=patients
  value=patients
  multiple=true
  placeholder="Choose some Pizzas"
}}

and my controller

patients: Ember.computed(function(){
  return this.store.findAll('patient')
}),

It sounds like I need to loop through the record from the database, either that or I need to follow a convention where the object needs to have an id, name and a description, I even tried to use "patient.name" but it won't work. I also tried to add the sample to a component "don't know why" but it made the whole app crashes and shows nothing but a white screen (no errors in the console).

Upvotes: 0

Views: 127

Answers (1)

Ember Freak
Ember Freak

Reputation: 12872

A mentioned in comment, ember-select2 is deprecated in favour of power-select addon. You can view great documentation for all possibilities.

{{#power-select-multiple
  options=patients
  selected=name
  placeholder="Select some names..."
  onchange=(action (mut name))
  as |patient|
}}
  {{patient.name}}
{{/power-select-multiple}}

and in controller,

patients: Ember.computed('model',function(){
  return this.store.findAll('patient')
}),

Here is the working twiddle for demonstration. to kick start your journey with power-select.

Upvotes: 1

Related Questions