<p>I'm working on a control panel plugin where I want to limit users to a subfolder within a main assets folder. I have the subfolder ID, but am unable to amend the following to make use of it:</p>

<pre><code>{{ forms.elementSelect({
    id: 'register',
    name: 'fields[register]',
    elementType: craft.elements.getElementType("Asset"),
    elements: register.register | default,
    criteria: {"kind":[],"localeEnabled":null,"locale":"en_gb"},
    jsClass: 'Craft.AssetSelectInput',
    addButtonLabel: 'Upload register',
    limit: 1,
    sources: ['folder:9'],
    disabled: register.locked | default
}) }}
</code></pre>

<p>So, for example, the folder ID above is a subfolder ID, but the asset ends up being saved within the main folder. If I revert back to the main folder ID, then everything works as expected.</p>

<p>To be fair, using this subfolder ID means existing assets aren't visible, which is the main reason I'm doing this anyway. But it would still be nice if this did what I wanted to.</p>

<p>Some more info:</p>

<ol>
<li>If the folder ID is a valid asset folder, it works as expected.</li>
<li>If the folder ID is a dynamically generated subfolder of a valid asset folder, the modal doesn't show any existing files but does allow uploads (saving them directly into the parent, which actually works nicely for me).</li>
<li>If the folder ID isn't a valid folder or subfolder, the modal is empty.</li>
</ol>

<p>Any ideas? This is kind of working from me, but more by accident.</p>

CC BY-SA 3.0
2016-06-14T05:46:12.060Z
There's a whitespace between ":" and "9" in "folder: 9". Is that a typo?
Andris Sevcenko
CC BY-SA 3.0
2016-06-14T06:45:32.223Z
Sorry, yes it is. I've updated.
Clive Portman
<plugin-development><assets><subfolder>
Limit control panel assets modal to a subfolder in plugin
# Limit control panel assets modal to a subfolder in plugin

(Asked by: username_0 on 2016-06-13)

I'm working on a control panel plugin where I want to limit users to a subfolder within a main assets folder. I have the subfolder ID, but am unable to amend the following to make use of it:
{{ forms.elementSelect({
    id: 'register',
    name: 'fields[register]',
    elementType: craft.elements.getElementType("Asset"),
    elements: register.register | default,
    criteria: {"kind":[],"localeEnabled":null,"locale":"en_gb"},
    jsClass: 'Craft.AssetSelectInput',
    addButtonLabel: 'Upload register',
    limit: 1,
    sources: ['folder:9'],
    disabled: register.locked | default
}) }}

So, for example, the folder ID above is a subfolder ID, but the asset ends up being saved within the main folder. If I revert back to the main folder ID, then everything works as expected.
To be fair, using this subfolder ID means existing assets aren't visible, which is the main reason I'm doing this anyway. But it would still be nice if this did what I wanted to.
Some more info:

If the folder ID is a valid asset folder, it works as expected.
If the folder ID is a dynamically generated subfolder of a valid asset folder, the modal doesn't show any existing files but does allow uploads (saving them directly into the parent, which actually works nicely for me).
If the folder ID isn't a valid folder or subfolder, the modal is empty.

Any ideas? This is kind of working from me, but more by accident.

**Tags:** plugin-development, assets, subfolder

> **Comments:**
> **username_1**: There's a whitespace between ":" and "9" in "folder: 9". Is that a typo?  
> **username_0**: Sorry, yes it is. I've updated.  

---

## 0 answers

