You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
I'm a bit confused because I totally missed that logic. Is it stated only in this vardoc? To be honest I think this is very unclear for the users (= "I require a file and the required number of files must be at least 0"). I would only add upgrade note for this one. @samdark what do you think?
Requiring to set minFiles might also confuse some users as its related to functionality you only need when you want the input to deal with multiple files (giving a specific $tooFew error message instead of the $uploadRequired message).
If you go looking in the API for required field functionality without knowing the design, the $uploadRequired parameter documents clearly how to set it. While I agree its not the best design and a bit implicit from the code alone, I'd favor backward compatibility in this case.
@bizley I think if ($filesCount === 0) would be enough. The field is defined as string only and similar code that uses validation texts does not check for null either.
What steps will reproduce the problem?
enableClientValidation = false
in the ActiveForm. (client side validation still works as expected and will prevent reproduction of the issue)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:yii2/framework/validators/FileValidator.php
Line 258 in 7c5b213
The text was updated successfully, but these errors were encountered: