Skip validation if file input does not exist (#13977)

This commit is contained in:
Evgeniy Moiseenko
2018-10-30 10:38:40 +03:00
committed by Alexander Makarov
parent 0f0e895475
commit 46c50e43c4
2 changed files with 6 additions and 3 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.16 under development
------------------------
- Bug #13977: Skip validation if file input does not exist (RobinKamps, s1lver)
- Bug #16183: Fixed when `yii\helpers\BaseFileHelper` sometimes returned wrong value (samdark, SilverFire, OndrejVasicek)
- Bug #13932: Fix number validator attributes comparison (uaoleg, s1lver)
- Bug #14039, #16636: Fixed validation for disabled inputs (s1lver, omzy83)

View File

@ -376,13 +376,15 @@ yii.validation = (function ($) {
return [];
}
// Continue validation if file input does not exist
var fileInput = $(attribute.input, attribute.$form).get(0);
// Skip validation if file input does not exist
// (in case file inputs are added dynamically and no file input has been added to the form)
if (typeof $(attribute.input, attribute.$form).get(0) === "undefined") {
if (typeof fileInput === "undefined") {
return [];
}
var files = $(attribute.input, attribute.$form).get(0).files;
var files = fileInput.files;
if (!files) {
messages.push(options.message);
return [];