<p>I am not expert in Craft CMS but this is how it works for me:</p>

<p>Depending on the element type, source is different.</p>

<p>Look at this link how Craft CMS implements this:</p>

<p><a href="https://github.com/craftcms/cms/blob/60881865f1b680c5aa5d4ad8f56d9a1ce3e452b0/src/fields/BaseRelationField.php#L842" rel="nofollow noreferrer">https://github.com/craftcms/cms/blob/60881865f1b680c5aa5d4ad8f56d9a1ce3e452b0/src/fields/BaseRelationField.php#L842</a></p>

<p>Now how assets implement inputsource function:</p>

<p><a href="https://github.com/craftcms/cms/blob/f83815cf28e7ce91edd501fc55ffd10f915a808e/src/fields/Assets.php#L550" rel="nofollow noreferrer">https://github.com/craftcms/cms/blob/f83815cf28e7ce91edd501fc55ffd10f915a808e/src/fields/Assets.php#L550</a></p>

<p>so the format of sources for asset is like:</p>

<pre><code>['folder:uid in volumefolders table']
</code></pre>

<p>and you can easily limit user to select assets from volumes you want.</p>

CC BY-SA 4.0
2019-10-29T10:12:26.963Z
Works like a dream, thank you so much for this – I'm just pretending to be a developer so only just learning how to wade through the Craft code to figure things out.
dmatthams
CC BY-SA 4.0
2019-10-29T11:04:33.800Z
@user3788089 you're welcome. Glad to hear that.
user9975
CC BY-SA 4.0
2019-10-29T09:46:44.313Z
2019-10-30T20:19:33.287Z
2019-10-30T20:19:33.287Z
user9975
<p>I'm building a module with a form that includes an element select field that I want to restrict to specific volume. So far this is what I have:</p>

<pre><code>{{ forms.elementSelectField({
    label: "Asset"|t('app'),
    id: 'images', 
    name: 'images',
    elementType: 'craft\\elements\\Asset',
    selectionLabel: "Choose"|t('app'),
    criteria: {
        kind: ['images']
    },
}) }}
</code></pre>

<p>I can see there is a 'sources' attribute, but I don't know how to structure the value. I've tried:</p>

<p><code>sources:[1]</code> and the handle <code>sources:['images']</code> without luck.</p>

<plugin-development><modules>
Restrict Sources on element select field
# Restrict Sources on element select field

(Asked by: username_0 on 2019-10-23)

I'm building a module with a form that includes an element select field that I want to restrict to specific volume. So far this is what I have:
{{ forms.elementSelectField({
    label: "Asset"|t('app'),
    id: 'images', 
    name: 'images',
    elementType: 'craft\\elements\\Asset',
    selectionLabel: "Choose"|t('app'),
    criteria: {
        kind: ['images']
    },
}) }}

I can see there is a 'sources' attribute, but I don't know how to structure the value. I've tried:
sources:[1] and the handle sources:['images'] without luck.

**Tags:** plugin-development, modules

---

## 1 answers

### Answer by username_1 on 2019-10-29. Score: 3 | Accepted answer

I am not expert in Craft CMS but this is how it works for me:
Depending on the element type, source is different.
Look at this link how Craft CMS implements this:
https://github.com/craftcms/cms/blob/60881865f1b680c5aa5d4ad8f56d9a1ce3e452b0/src/fields/BaseRelationField.php#L842
Now how assets implement inputsource function:
https://github.com/craftcms/cms/blob/f83815cf28e7ce91edd501fc55ffd10f915a808e/src/fields/Assets.php#L550
so the format of sources for asset is like:
['folder:uid in volumefolders table']

and you can easily limit user to select assets from volumes you want.

> **Comments:**
> **username_0**: Works like a dream, thank you so much for this – I'm just pretending to be a developer so only just learning how to wade through the Craft code to figure things out.  
> **username_1**: @user3788089 you're welcome. Glad to hear that.  

---

