Skip to content

Regression in FileValidator since Yii 2.0.50 when validating required files #20231

Closed
@marcovtwout

Description

@marcovtwout

What steps will reproduce the problem?

['example', 'file', 'skipOnEmpty' => false],
  • Set enableClientValidation = false in the ActiveForm. (client side validation still works as expected and will prevent reproduction of the issue)
  • Post the form without selecting any file.

What is the expected result?

A validation error 'Please upload a file'.

What do you get instead?

The validation passes.

Additional info

The regression is introduced by the changes to validateAttribute() in #20167 which were released with Yii 2.0.50. It still works as expected on 2.0.49.

@bizley Since skipOnEmpty is set to false, validateOnAttribute() is called and should still handle the case where no file has been uploaded. The validation should be executed even if $minFiles is still set to the default of 0. Previously, this happened here, but this code is not reached anymore in the given scenario:

return [$this->uploadRequired, []];

Q A
Yii version 2.0.50
PHP version -
Operating system -

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions