Skip to content

Conversation

@godismyjudge95
Copy link
Contributor

@godismyjudge95 godismyjudge95 commented Jul 23, 2025

This is a 6.x port of this PR - #11648

It resolves:


We've had a number of clients contact us with confusion about the validation errors that are shown when using asset validation rules. Specifically things like the dimensions rule or mime type cause confusion when it just gives a generic "invalid data" error instead of telling you what asset is invalid and why.

This PR solves that by doing three things:

  • change the asset validation rules away from whole field validation rules to be single attribute Laravel rules instead
  • apply the validation rules (on the assets field only) to the items in the field instead of just the field itself
  • display the validation messages on each asset

In theory everything should work the same - I only had to change a single test which called the ->passes() method directly on the dimension rule.

Here is a what it looks like with invalid assets:

image

The asset grid does not appear to be styled for me, so I assume that is still under development. I wanted to get these changes PR'd though so whoever is working on that can incorporate them into it.


Update: the UI looks much better now.

image

Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind please keeping the scope of this PR to showing the individual asset validation errors?

Please separate the changes to the rules themselves into a separate PR. The rules we're using are based on native Laravel validation.

@godismyjudge95
Copy link
Contributor Author

Would you mind please keeping the scope of this PR to showing the individual asset validation errors?

Please separate the changes to the rules themselves into a separate PR. The rules we're using are based on native Laravel validation.

I believe those changes are necessary to get the assets to individually validate. The way the rules were set up currently I could not get separate validation messages for each asset. I may have overlooked a way to do so; I will double check.

@jasonvarga
Copy link
Member

Sorry I mean, the classes can change if they need to, but the logic/messages shouldn't. e.g. The dimensions rule should continue to just say "invalid image dimensions" - not give specific "must have a ratio of x" etc messages.

@godismyjudge95
Copy link
Contributor Author

Sorry I mean, the classes can change if they need to, but the logic/messages shouldn't. e.g. The dimensions rule should continue to just say "invalid image dimensions" - not give specific "must have a ratio of x" etc messages.

Oh ok, yeah I can revert that

@godismyjudge95
Copy link
Contributor Author

Uh... I think these tests failing are unrelated? I just merged from master and now it's failing. 🫠

@duncanmcclean
Copy link
Member

Don't worry about failing tests from master. We'll fix them and merge it in before reviewing 👍

Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I noticed is that if you set a max_files, you now get this incorrect validation error:

Image

@godismyjudge95
Copy link
Contributor Author

Something I noticed is that if you set a max_files, you now get this incorrect validation error:

Good catch! I think I now have all of the whole field validation rules listed here now:
https://github.com/statamic/cms/pull/11988/files#diff-22bb4c9ddfb67b736e92de38ac9fffc06904031c853cae90b1f35e270e04021eR150

if (Str::of($rule)->before(':')->is(['array', 'required', 'nullable', 'max', 'min'])) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants