silverstripe / silverstripe-asset-admin

Silverstripe assets gallery for asset management
BSD 3-Clause "New" or "Revised" License
19 stars 78 forks source link

UploadField doesn't validate allowed extensions with "choose existing" option #1434

Open mark-a-j-adriano opened 5 months ago

mark-a-j-adriano commented 5 months ago

Module version(s) affected

2.1.3

Description

Allowed extensions validation for UploadField does not kick in when using the "choose existing" option

https://github.com/silverstripe/silverstripe-asset-admin/assets/11882563/9f2a02f8-ed41-4552-8359-684d4e418304

How to reproduce

  1. Add an upload field like this to a form:
    /** @var UploadField $logo */
    $logo = UploadField::create('Logo', 'Logo');
    $logo->setAllowedExtensions(['png', 'svg'])
        ->setAllowedMaxFileNumber(1)
        ->setUploadEnabled(false)
        ->setDescription('Accepts PNG or SVG image format.');
  2. Add a file (not png or svg) to the field using the "choose existing" option
  3. Note that the file is added to the field without raising a validation error.

NOTE the setAllowedMaxFileNumber is probably unrelated, and setUploadEnabled is not necessary.

Possible Solution

No response

Additional Context

No response

Validations

Notes

Acceptance criteria

UX questions