Sorting files alphabetically after upload

I’ve looked at other topics but couldn’t find an answer to this. Is there a way to have the files sorted alphabetically, once they’re uploaded? They’re actually shown alphabetically in the upload progress view.

Use case: my client has event pictures that she preselects by changing the file name. She then uploads and would like to keep the order, however be able to change the order once uploaded.

The files section allows sorting: Files section | Kirby CMS

Thanks! True, however not in the files field…? This is what I’d need to achieve.

Well, a files field is a select field and the data is stored in the order in which they are selected, not in alphabetical order. You could sort them alphabetically on save, but then you’d lose the option to sort them manually.

That’s the problem. Do you know how they are sorted when uploading?

Not sure I understand the question. Let’s say you have uploaded a set of files like this:

pixel1.jpg
pixel2.jpg
pixel3.jpg
pixel4.jpg

Now in your files field, you select pixel1, pixel3, and pixel4. Then they will show up in the files field like this:

Screen Shot 2022-08-29 at 22.49.51

That is, in alphabetical order like selected.

However, if you later select pixel2, it will be appended to this list:
Screen Shot 2022-08-29 at 22.52.57

You could sort them alphabetically again in a $page->update() hook, however, then any manual sorting would be gone as well.

Maybe it would make more sense to use a files section?

Hmm, I need to check out the section then. My issue is this: I have a files field in a gallery:

When I drag and drop or upload them, they appear randomly, which is kind of bizarre. I’ve tried selecting them in order before dragging them, but that doesn’t help. I can, certainly, upload them one by one but that’s cumbersome with 30+ pics.