<p>If I'm interpreting 'craft.js' correctly, there doesn't seem to be any way to do this, at least not via craft methods. Apart from passing in the initial settings parameter, everything else looks like protected methods.</p>

<p>You could potentially do it manually through javascript however by triggering a 'click' event on the elements directly. You would have to wait until the elements are loaded first however.</p>

<pre><code>$('.elements tr[data-id="2201"]').trigger('click');
</code></pre>

CC BY-SA 3.0
2015-02-24T07:21:51.543Z
Thanks Douglas but that's not enough in my case. It will just visually highlight the elements, but the modal won't know that it's selected, thus won't include it into selected items when saving.
Stalinko
CC BY-SA 3.0
2015-02-24T08:24:45.950Z
I suspect that the modal is just responding to mouse and keyboard events via listeners and then adding items to the selectedItems list, which you should be able to trigger programatically. The problem is tracking down which events to trigger on which elements in what order, which is not an easy task. In the end your right though, probably a dead end.
Douglas McDonald
CC BY-SA 3.0
2015-02-23T07:02:15.987Z
2015-02-23T07:16:27.757Z
2015-02-23T07:16:27.757Z
Douglas McDonald
<p>I'm showing a modal using "createElementSelectorModal()"</p>

<p>In some cases I need to pass ids of elements which should be selected right after the modal is created. Is it possible?</p>

CC BY-SA 3.0
2015-05-29T13:42:14.177Z
@JamieWade In case you don't get the notification, I left a comment on your "Craft tag" meta question, would be nice if you could reply there! Thx
carlcs
<plugin-development><elementtype><modal>
How to set selected elements when creating modal with "createElementSelectorModal()"?
# How to set selected elements when creating modal with "createElementSelectorModal()"?

(Asked by: username_0 on 2015-02-22)

I'm showing a modal using "createElementSelectorModal()"

In some cases I need to pass ids of elements which should be selected right after the modal is created. Is it possible?

**Tags:** plugin-development, elementtype, modal
> **Comments:**
> **username_1**: @JamieWade In case you don't get the notification, I left a comment on your "Craft tag" meta question, would be nice if you could reply there! Thx  

---

## 1 answers

### Answer by username_2 on 2015-02-23. Score: 1

If I'm interpreting 'craft.js' correctly, there doesn't seem to be any way to do this, at least not via craft methods. Apart from passing in the initial settings parameter, everything else looks like protected methods.
You could potentially do it manually through javascript however by triggering a 'click' event on the elements directly. You would have to wait until the elements are loaded first however.
$('.elements tr[data-id="2201"]').trigger('click');

> **Comments:**
> **username_0**: Thanks Douglas but that's not enough in my case. It will just visually highlight the elements, but the modal won't know that it's selected, thus won't include it into selected items when saving.  
> **username_2**: I suspect that the modal is just responding to mouse and keyboard events via listeners and then adding items to the selectedItems list, which you should be able to trigger programatically. The problem is tracking down which events to trigger on which elements in what order, which is not an easy task. In the end your right though, probably a dead end.  

---

