1

I'm trying to close the select box before it executes the search with Ember Power Select. I'm assuming the user knows what he is looking for if he paste a list and automatically sets the selected items.

I tried to use select.actions.close() but it seems that it is related to the onClose() event. I also try to use the property opened but changing it did not show any difference.

My component

{{#power-select-multiple
        renderInPlace=true
        search=(action "mySearch")
        selected=selected_item
        onchange=(action (mut selected_item))
        oninput=(action "checkPastingMultipleElements")
        opened=checkSelect
        as |name|
}}
    {{name}}
{{/power-select-multiple}}

my action

checkPastingMultipleElements(text, select) {
        this.set('selecteded_item', [text]);
        // error
        // select.actions.close()

        // does nothing
        // if (text.length === 4) { this.set('checkSelect', false); }            

        return false; // if true, it executes the search
}
renno
  • 2,659
  • 2
  • 27
  • 58

1 Answers1

3

Your initial guess was right, using select.actions.close is possible, but you have to enqueue this in the runloop to avoid a double-render problem.

Also, if what you want to do is to select a value and close the select, select.actions.choose is exactly what you want.

  checkPastingMultipleElements(text, select) {
    Ember.run.scheduleOnce('actions', null, select.actions.choose, [text]);
  }
miguel.camba
  • 1,777
  • 1
  • 14
  • 19
  • 1
    First of all, thanks for developing this incredible addon. Second, thanks for the answer it led me to the right answer. The reason I needed to use `close()` is because I have to split the text in multiple choices and not only one. This way I could do `this.set('selected_item', text.split(" "));` – renno Dec 07 '16 at 15:16
  • Also, I noticed that with the original answer (using choose), it throws an error whenever I delete the text `"Assertion Failed: \`{{power-select-multiple}}\` requires a \`searchField\` when the options are not strings to remove options using backspace"`. – renno Dec 07 '16 at 15:21
  • Yes, that is correct. By example `{{power-select-multiple searchField="name"}}`. This made me realise that the documentation doesn't mention this. I should update it. – miguel.camba Dec 28 '16 at 11:01