cms icon indicating copy to clipboard operation
cms copied to clipboard

Form: File Maxsize Validation rule doesn't contain the attribute key

Open ahinkle opened this issue 3 years ago • 3 comments

Bug description

When using max_filesize validation rule, it doesn't contain the attribute key. It only displays the ending message, "May not be greater than 3000 kilobytes." which isn't particularly helpful. Typically you would see with the validation rules the applied attribute key. e.g. "The User Profile Photo may not be greater than 3000 kilobytes."

I do not have modified validation keys (standard ones in Laravel)

How to reproduce

  • Create a form
  • Add a rule for file size < 3000 kB.
  • Publish the form
  • Complete the form and upload an image larger than 3000 kB.
  • See error bag for message: May not be greater than 3000 kilobytes.

Logs

Xnapper-2022-06-27-13 49 00
Standard Laravel Validation file:


    'max' => [
        'numeric' => 'The :attribute may not be greater than :max.',
        'file' => 'The :attribute may not be greater than :max kilobytes.',
        'string' => 'The :attribute may not be greater than :max characters.',
        'array' => 'The :attribute may not have more than :max items.',
    ],


Standard Statamic Validation language file:
    'max'                  => [
        'numeric' => 'May not be greater than :max.',
        'file'    => 'May not be greater than :max kilobytes.',
        'string'  => 'May not be greater than :max characters.',
        'array'   => 'May not have more than :max items.',
    ],

Versions

Statamic 3.3.6 Pro Laravel 9.17.0 PHP 8.1.6 optimoapps/statamic-bard-text-align 1.0.2

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

No response

Additional details

No response

ahinkle avatar Jun 27 '22 18:06 ahinkle

What's in your lang/en/validation.php file?

jasonvarga avatar Jun 27 '22 19:06 jasonvarga

What's in your lang/en/validation.php file?

Hey @jasonvarga,

Thanks for the quick reply. I added that to the original post but nothing has been modified from the original Laravel installation and Statamic installation:

resources/lang/en/validation.php:

    'max' => [
        'numeric' => 'The :attribute may not be greater than :max.',
        'file' => 'The :attribute may not be greater than :max kilobytes.',
        'string' => 'The :attribute may not be greater than :max characters.',
        'array' => 'The :attribute may not have more than :max items.',
    ],

I do not have a language file posted that overrides the default Statamic validation language file.

ahinkle avatar Jun 27 '22 19:06 ahinkle

Okay thanks, I see the issue.

The custom image validation rules are currently using the statamic namespaced translations. https://github.com/statamic/cms/blob/b2b108c6fda387ba02a25d1963bc4240987a6ae6/src/Fieldtypes/Assets/MaxRule.php#L25

It should only be doing that when inside the control panel.

jasonvarga avatar Jun 27 '22 19:06 jasonvarga