diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 57618af6bd..936a09e126 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -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) diff --git a/framework/assets/yii.validation.js b/framework/assets/yii.validation.js index a2b88849f3..f0118f4443 100644 --- a/framework/assets/yii.validation.js +++ b/framework/assets/yii.validation.js @@ -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 [];