Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-29T10:12:26.963Z
Answers.Text: 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.
Answers.UserDisplayName: dmatthams
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-29T11:04:33.800Z
Answers.Text: @user3788089 you're welcome. Glad to hear that.
Answers.UserDisplayName: user9975
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-29T09:46:44.313Z
Answers.LastActivityDate: 2019-10-30T20:19:33.287Z
Answers.LastEditDate: 2019-10-30T20:19:33.287Z
Answers.UserDisplayName: user9975
Body: <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>
  
Tags: <plugin-development><modules>
Title: Restrict Sources on element select field
ThreadText: # 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.  
  
  ---
  
  