1

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
}) }}
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.