<p>Elements can be manually enabled/disabled from the modal after it has been initialized using the following methods:</p>

<pre><code>myModal.elementIndex.enableElementsById(elementIds);
</code></pre>

<p>and</p>

<pre><code>myModal.elementIndex.disableElementsById(elementIds);
</code></pre>

<p>Both functions accept a number (single element ID) or an array of numbers (multiple element IDs).</p>

CC BY-SA 3.0
2014-07-11T20:47:40.127Z
Thanks Brandon, I appreciate the quick response. I'm not 100% sure I'm using this correctly. If I didn't want the modal to pop up automatically and I wanted to reuse the modal if my Field Type plugin is added to the page multiple times, how would I go about this?
Peter Tell
CC BY-SA 3.0
2014-07-11T21:30:59.347Z
Just don’t create the modal in your JS until it’s actually needed.
Brandon Kelly
CC BY-SA 3.0
2014-07-11T21:33:07.047Z
Fair enough, that is kind of what I'm doing. I wrapped a function around creating the modal and call it on a click event, passing in the parameters I need. Thanks again!
Peter Tell
CC BY-SA 3.0
2014-07-11T19:54:57.990Z
2014-07-11T19:54:57.990Z
Brandon Kelly
<p>Well, this probably wasn't the best way to go about it, but I solved this by manually defining what is un-selectable:</p>

<pre><code>var unSelectable = [1,2,3]
</code></pre>

<p>And then I keep track of the array as things happen in the DOM and pop items in and out. Then, I pass them to the function I use to call Craft.createElementSelectorModal() setting disabledElementIds manually:</p>

<pre><code>disabledElementIds: unSelectable,
</code></pre>

CC BY-SA 3.0
2014-07-11T21:30:31.420Z
2014-07-11T21:30:31.420Z
Peter Tell
<p>I'm using the createElementsSelectorModal to access certain element types as described by Brandon <a href="https://craftcms.stackexchange.com/questions/895/is-it-possible-to-use-the-elementtype-modal-ui-for-a-custom-field-type-plugin">here</a></p>

<p>With this implementation, how would I clear out "disabledElementIds"? So that if an Entry is added and then removed I can tell the Modal it should be selectable again. </p>

<p>Thanks!</p>

<plugin-development>
How would I change "disabledElementIds" when using createElementSelectorModal()?
# How would I change "disabledElementIds" when using createElementSelectorModal()?

(Asked by: username_0 on 2014-07-11)

I'm using the createElementsSelectorModal to access certain element types as described by Brandon [here](https://craftcms.stackexchange.com/questions/895/is-it-possible-to-use-the-elementtype-modal-ui-for-a-custom-field-type-plugin)

With this implementation, how would I clear out "disabledElementIds"? So that if an Entry is added and then removed I can tell the Modal it should be selectable again.

Thanks!

**Tags:** plugin-development


---

## 2 answers

### Answer by username_1 on 2014-07-11. Score: 3 | Accepted answer

Elements can be manually enabled/disabled from the modal after it has been initialized using the following methods:
myModal.elementIndex.enableElementsById(elementIds);

and
myModal.elementIndex.disableElementsById(elementIds);

Both functions accept a number (single element ID) or an array of numbers (multiple element IDs).

> **Comments:**
> **username_0**: Thanks Brandon, I appreciate the quick response. I'm not 100% sure I'm using this correctly. If I didn't want the modal to pop up automatically and I wanted to reuse the modal if my Field Type plugin is added to the page multiple times, how would I go about this?  
> **username_1**: Just don’t create the modal in your JS until it’s actually needed.  
> **username_0**: Fair enough, that is kind of what I'm doing. I wrapped a function around creating the modal and call it on a click event, passing in the parameters I need. Thanks again!  

---

### Answer by username_0 on 2014-07-11. Score: 1

Well, this probably wasn't the best way to go about it, but I solved this by manually defining what is un-selectable:
var unSelectable = [1,2,3]

And then I keep track of the array as things happen in the DOM and pop items in and out. Then, I pass them to the function I use to call Craft.createElementSelectorModal() setting disabledElementIds manually:
disabledElementIds: unSelectable,


---

