Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selected options is undefined after model save #1527

Open
usamahamed opened this issue Jul 26, 2022 · 1 comment
Open

Selected options is undefined after model save #1527

usamahamed opened this issue Jul 26, 2022 · 1 comment

Comments

@usamahamed
Copy link

I have item model that has relationship tags and i use multiple power select component for rendering these tags in the item page like the following:

    <PowerSelectMultiple
        @options={{@names}}
        @selected={{@selected}}
        @triggerComponent={{component "utils/ps-trigger" areAllSelected=this.areAllSelected}}
        @optionsComponent={{component "utils/ps-option"}}
        @onChange={{fn (mut @selected)}}
        @searchEnabled={{0}}
    as |entry|
    >
        {{entry.safeLabel}}
    </PowerSelectMultiple>

inside the trigger component:

<div class="m-ps__plus h-icon-plus m-icon-add__medium h-link-no-hover {{if @areAllSelected "disabled" }}" title={{if @areAllSelected (t "catalogs.tags.no-more-categories") (t "catalogs.tags.select-categories")}}>{{svg-jar "#highlightplus"}}</div>
{{this.isSelected}}
<ul id="ember-power-select-multiple-options-{{@select.uniqueId}}" class="ember-power-select-multiple-options"
    {{on "touchstart" this.chooseOption}}
    {{on "mousedown" this.chooseOption}}
>
    {{#each @select.selected as |opt idx|}}
        <li class="m-ps__item ember-power-select-multiple-option {{if opt.disabled "ember-power-select-multiple-option--disabled"}}">
            {{#unless @select.disabled }}
                <span
                      aria-label={{t "categories.remove"}}
                      class="ember-power-select-multiple-remove-btn"
                      data-selected-index={{idx}}>
                    {{t "categories.x"}}
                </span>
            {{/unless}}
            {{#if @selectedItemComponent}}
                {{component @selectedItemComponent extra=(readonly this.extra) option=(readonly opt) select=(readonly @select)}}
            {{else}}
                {{yield opt @select}}
            {{/if}}
        </li>
    {{else}}
        {{#if (and @placeholder (not @searchEnabled))}}
            <span class="ember-power-select-placeholder">{{@placeholder}}</span>
        {{/if}}
    {{/each}}
</ul>

The problem is with the new ember-data version, saving relationship inside the model with ember-changeset returns PromiseManyArray which i suspect, it causes the power select options to be undefined inside the ps-trigger component

image

I am not sure if this is related to this ember-data ticket https://github.com/emberjs/data/issues/8024 because it breaks only from ember-data version 3.28

Environment Info:

Ember env:
ember-source: 4.5.0
ember-cli: 4.4.0
ember-data: 4.4.0
ember-power-select: 5.0.4
ember-changeset: 4.1.0
System:
OS: macOS 11.6.7
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
Node: 16.15.0 - ~/.volta/tools/image/node/16.15.0/bin/node
Yarn: 1.22.19 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
npm: 7.24.2 - ~/roomle-pdc-upgrade/node_modules/.bin/npm
Browsers:
Chrome: 103.0.5060.134
Firefox: 102.0.1
Safari: 15.5

@usamahamed
Copy link
Author

Looks like this also related adopted-ember-addons/ember-changeset#281 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant