Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-24T07:21:51.543Z
Answers.Text: 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.
Answers.UserDisplayName: Stalinko
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-24T08:24:45.950Z
Answers.Text: 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.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-23T07:02:15.987Z
Answers.LastActivityDate: 2015-02-23T07:16:27.757Z
Answers.LastEditDate: 2015-02-23T07:16:27.757Z
Answers.UserDisplayName: Douglas McDonald
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-29T13:42:14.177Z
Comments.Text: @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
Comments.UserDisplayName: carlcs
Tags: <plugin-development><elementtype><modal>
Title: How to set selected elements when creating modal with "createElementSelectorModal()"?
ThreadText: # 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 username_2 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.  
  
  ---
  
  