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?

  • @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
    May 29, 2015 at 13:42

1 Answer 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');
  • 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
    Feb 24, 2015 at 7:21
  • 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. Feb 24, 2015 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.