Kirby3 panel select box allows adding files that should be prevented based on accept types

Hi all,

Hoping this isn’t a Kirby bug, but more of me just overlooking something obvious in my Blueprints… I have a specific File Blueprint for Hero Images like so:

title: Hero Image

accept:
  mime: image/jpeg, image/png

And then in my Page Blueprint, I have the following reference in my fields:

heroImage:
  type: files
  label: Hero Image
  max: 1
  multiple: false
  required: true
  layout: cards
  size: huge
  image:
    ratio: 16/9
    cover: true
  uploads:
    template: hero-image

When I’m in the panel and I click the + Add / Upload option, the computer dialogue pops up and it allows only jpg/png files to be selected, all other file types are disabled / dimmed out which is perfect!

But then if I click the + Add / Select option (or click the empty file field), the Kirby file selection dialogue pops up and I can choose from other files I’ve already uploaded - but any and all file types are selectable, so for example, I can select a video / .mp4 or some other non-accepted image file type.

I understand in the blueprint example above that I have the Upload Property defining what to do when uploading a file, but what about selecting a file?

Hope this makes enough sense (first time posting here).

Thank you all for your help :jack_o_lantern::+1:

Hi,

just add template: hero-image to Your field.
It will filter the select option by the template, that the files have been uploaded with.

heroImage:
  type: files
  label: Hero Image
  max: 1
  multiple: false
  required: true
  layout: cards
  size: huge
  template: hero-image
  image:
    ratio: 16/9
    cover: true
  uploads:
    template: hero-image

Thanks for the quick advice, @Cris! I tried this though, and it didn’t change anything… still allows any file to be selected.

Looking at the field properties, I don’t see template as an option, so I’m guessing this gets ignored: https://getkirby.com/docs/reference/panel/fields/files#field-properties

Oh, sorry, I setup Your example incorrectly (have added Your heroImage in a section instead of putting it under fields…),
so, then You could add a query instead:

heroImage:
  type: files
  label: Hero Image
  max: 1
  multiple: false
  required: true
  layout: cards
  size: huge
  query: page.images.filterBy('template', 'hero-image')
  image:
    ratio: 16/9
    cover: true
  uploads:
    template: hero-image
1 Like

Nice!! Thanks @Cris, that was it!

Now, if I have a video template would it just be like:

query: page.videos.filterBy('template', 'video')

If You gave Your video files a template called video then yes.
Otherwise I think, kirby will fallback to the default template.

Have a look at the filterBy() function.

PS: You could also filterBy filetypes =)

1 Like

Right, thanks! That part makes sense, I should’ve clarified…

query: page.images would be query: page.files because there is no query: page.videos correct?

I haven’t tested it with videos, since I never have uploaded videos to a kirby project, but I think it should work since the object exists.
But page.files works definetely =)
(Hope I don’t talk too much nonesense, I’m not a kirby- / php pro, correct me if I’m wrong…) :upside_down_face:

Haha no worries! Your answers were spot on, much appreciated! The filterBy() link is great - that was super helpful :sunglasses:

I just tested the videos object - any of these following options will pass:

query: page.files.filterBy('template', 'video')
query: page.videos.filterBy('template', 'video')
query: page.videos.filterBy('extension', 'mp4')

Thanks again!

1 Like