question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with default selected state for an object

See original GitHub issue

I just switched from using select2 to this addon and it’s awesome! Everything has worked great except for the default “selected” state. I’m not sure if this is a bug or if I’m doing something wrong on my end. Here is the code I’m working with:

Template:

{{#power-select
  options=repos
  selected=selectedRepo
  onchange=(action (mut selectedRepo))
  placeholder="Select repo"
  searchField="name"
  as |repo|}}
  {{repo.name}}
{{/power-select}}

Controller data:

repos: Ember.A([
  { name: 'ember', id: 'emberjs/ember.js' },
  { name: 'angular', id: 'angular/angular' },
  { name: 'backbone', id: 'jashkenas/backbone' },
  { name: 'knockout', id: 'knockout/knockout' }
]),

selectedRepo: { name: 'ember', id: 'emberjs/ember.js' }

There seems to be an issue with the equality statement for the selected value: https://github.com/cibernox/ember-power-select/blob/master/addon/helpers/ember-power-select-option-classes.js#L11. If you manually select a different item from the dropdown list the selected state successfully works. It just doesn’t work for the default selected state.

You can see a demo of this issue here: http://gregjopa.me/ember-reporting-dashboard/#/details. Demo code: https://github.com/gregjopa/ember-reporting-dashboard

Versions: Ember: 1.13.11 ember-power-select: 0.5.2

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
cibernoxcommented, Jun 10, 2019

@devop911 that said, I think I don’t oppose to your idea anymore, as long with the same option can take both a property name or a function to be invoked with the option.

Property name:

<PowerSelect @options={{opts}} @selected={{thing}} @onChange={{action (mut thing)}} @isEqual="id" as |opt|>
  {{opt}}
</PowerSelect}}

Function:

<PowerSelect @options={{opts}} @selected={{thing}} @onChange={{action (mut thing)}} @isEqual={{this.compareOptions}} as |opt|>
  {{opt}}
</PowerSelect}}
compareFunctions(o1, o2) {
  return o1.id === o2.id; // The compare function could be arbitrarily complex this way.
}
0reactions
JanAckermanncommented, Jun 10, 2019

This is a loveley Idea! Would love to see it in next version

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - MUI Object in Select default value not showing but ...
As Ivan has stated, the reason why your Select component isn't showing the selected value is because the selected value is a different...
Read more >
[V2] Default value must be object · Issue #2841 - GitHub
Trying to initialize the Select with a simple {value: '1'} without a label doesn't work as it expects the label. Perhaps I am...
Read more >
Object State does not return to Normal (default state)
Hi, I have 2 buttons set up to change the state of an object from Normal to state 1 or state 2 depending...
Read more >
How to set default value in select using ReactJS
You can use an attribute defaultValue to set the default value in the Select menu If none option is integrated with this attribute...
Read more >
Select API - Material UI - MUI
Name Type Default autoWidth bool false children node classes object
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found