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:

  1. If the folder ID is a valid asset folder, it works as expected.
  2. 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).
  3. 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.

  • There's a whitespace between ":" and "9" in "folder: 9". Is that a typo? – Andris Sevcenko Jun 14 '16 at 5:46
  • Sorry, yes it is. I've updated. – Clive Portman Jun 14 '16 at 6:45

Your Answer

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

Browse other questions tagged or ask your own question.