Answers.Body: <p>Sadly there is very little documentation around this. Use <code>criteria</code> like this. I've also tested <code>siteId</code> which worked. I'm sure there are more criterias available.</p>
  <pre><code>{{ forms.elementSelectField({
    label: 'Blog post',
    name: 'blogpost',
    elementType: 'craft\\elements\\Entry',
    selectionLabel: 'Select your blog post',
    showSiteMenu: true,
    criteria: {
        section: ['blogposts'],
        siteId: 1
    },
    limit: 1,
    required: true
  }) }}
  </code></pre>
  <p><a href="https://github.com/craftcms/cms/blob/60881865f1b680c5aa5d4ad8f56d9a1ce3e452b0/src/fields/BaseRelationField.php#L843" rel="nofollow noreferrer">Link to the relevant Craft CMS source code.</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-28T06:48:32.177Z
Answers.LastActivityDate: 2021-10-28T06:48:32.177Z
Answers.UserDisplayName: PWL
Body: <p>How do I limit this elementSelectField to only allow entries within a certain section?</p>
  <pre><code>{{ forms.elementSelectField({
    label: 'Blog post',
    name: 'blogpost',
    elementType: 'craft\\elements\\Entry',
    selectionLabel: 'Select your blog post',
    showSiteMenu: true,
    limit: 1,
    required: true
  }) }}
  </code></pre>
  
Tags: <craft3><plugin-development><form>
Title: Limit elementSelectField to specific sections
ThreadText: # Limit elementSelectField to specific sections
  
  (Asked by: username_0 on 2021-10-28)
  
  How do I limit this elementSelectField to only allow entries within a certain section?
  
  ```
  {{ forms.elementSelectField({
    label: 'Blog post',
    name: 'blogpost',
    elementType: 'craft\\elements\\Entry',
    selectionLabel: 'Select your blog post',
    showSiteMenu: true,
    limit: 1,
    required: true
  }) }}
  
  ```
  
  **Tags:** craft3, plugin-development, form
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-10-28. Score: 1 | Accepted answer
  
  Sadly there is very little documentation around this. Use `criteria` like this. I've also tested `siteId` which worked. I'm sure there are more criterias available.
  
  ```
  {{ forms.elementSelectField({
    label: 'Blog post',
    name: 'blogpost',
    elementType: 'craft\\elements\\Entry',
    selectionLabel: 'Select your blog post',
    showSiteMenu: true,
    criteria: {
        section: ['blogposts'],
        siteId: 1
    },
    limit: 1,
    required: true
  }) }}
  
  ```
  
  [Link to the relevant Craft CMS source code.](https://github.com/craftcms/cms/blob/60881865f1b680c5aa5d4ad8f56d9a1ce3e452b0/src/fields/BaseRelationField.php#L843)
  
  
  ---
  
  