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.

Possible bugs with EPS v4.0.0-beta.2

See original GitHub issue

Hello. I’m following an Ember tutorial and rewriting the app in Octane (Ember v3.13.1) as I go. I met two problems when it was time to introduce EPS and I wanted to try out the latest 4.0.0-beta.2.

If you have questions or need clarifications, feel free to let me know. You can find my latest code here: https://github.com/ijlee2/Tutorials/tree/master/ember-embercasts-library-ui. Thanks!

1. Compile error: assign is not a helper

Once I added a <PowerSelect> in a template, I encountered the error above. On Ember Discord, madnificent kindly pointed out that one needed to install ember-assign-helper.

This addon is currently listed under devDependencies in package.json. Does it need to be under dependencies instead?

2. Unable to click on an option if I provide an array of Ember Data records

When @options is an array of Ember Data records, the selectAuthor below doesn’t get called when I click on an option. However, if I use the arrow keys and Enter to select, the action is called.

I think the problem only occurs with an array of ED records. If this.model is an array of strings or an array of POJOs, I am able to call the action with mouse or Enter key.

Similarly, when I pass to @search an action that returns an array of ED records, I am unable to click on an option.

// Route template

...
<PowerSelect
    @options={{this.model}}
    @selected={{this.selectedAuthor}}
    @onChange={{this.selectAuthor}}
    as |author|
>
    {{author.lastName}}, {{author.firstName}}
</PowerSelect>
...
// Route handler

import Route from '@ember/routing/route';

export default class BooksCreateRoute extends Route {
    model() {
        return this.store.findAll('author');
    }
}
// Controller

import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

export default class BooksCreateController extends Controller {
    @tracked selectedAuthor;

    @action
    selectAuthor(author) {
        this.selectedAuthor = author;
    }
}

Temporary workaround

In case there are others who want to work with EPS and ED, I’ll post my temporary solution here:

// Route template

...
<PowerSelect
    @selected={{this.selectedAuthor}}
    @searchEnabled={{true}}
    @search={{this.searchAuthor}}
    @onChange={{this.selectAuthor}}
    as |author|
>
    {{author.lastName}}, {{author.firstName}}
</PowerSelect>
...
// Route handler

import Route from '@ember/routing/route';

export default class BooksCreateRoute extends Route {
    model() {
        return {
            title: '',
            isbn: '',
            publicationDate: null,
            author: null
        };
    }
}
// Controller

import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

export default class BooksCreateController extends Controller {
    @tracked selectedAuthor;

    @action
    async searchAuthor(query) {
        const authors = await this.store.query('author', {
            filter: { query }
        });

        // Ember Power Select v4.0.0-beta.2 does not handle an array of
        // Ember Data models as options. To get around this issue, we can
        // return an array of POJOs and keep a record of searched authors.
        this.possibleAuthors = authors;

        return authors.map(author => ({
            id: author.id,
            firstName: author.firstName,
            lastName: author.lastName
        }));
    }

    @action
    selectAuthor(author) {
        this.model.author = this.possibleAuthors.find(possibleAuthor => {
            return possibleAuthor.id === author.id;
        });

        this.selectedAuthor = author;
    }

    @action
    saveBook(event) {
        event.preventDefault();

        const book = this.store.createRecord('book', this.model);

        book
            .save()
            .then(() => {
                this.transitionToRoute('books');
            });
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
MikiDicommented, Nov 24, 2019

I can confirm both. For nr. 2 I believe it’s here where things go wrong. Looks like direct use of objectAt was dropped a whole while ago (#bf87418148c2dc75aa9a0c74c4c164284c66bb11, PR #534 ) ( @madnificent You’re mentioned up here ^ 👍 )

0reactions
lucacorticommented, Dec 9, 2019

@cibernox The selected choice label is still not updating correctly for me in b6 when clearing the selection.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImageMagick-7.0.7-19-Q16-x64-dll.exe - Hybrid Analysis
Malicious Indicators 7 · Checks for a resource fork (ADS) file. details: "iexplore.exe" checked file "C:" · Contains ability to reboot/shutdown the operating ......
Read more >
https://raw.githubusercontent.com/vitejs/vite/main...
This is meaningful for Vite's framework-agnostic story, and will allow us to build independent teams to maintain each of the plugins. If you...
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