Skip to content

Commit 46c50e4

Browse files
s1lversamdark
authored andcommitted
Skip validation if file input does not exist (#13977)
1 parent 0f0e895 commit 46c50e4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Yii Framework 2 Change Log
44
2.0.16 under development
55
------------------------
66

7+
- Bug #13977: Skip validation if file input does not exist (RobinKamps, s1lver)
78
- Bug #16183: Fixed when `yii\helpers\BaseFileHelper` sometimes returned wrong value (samdark, SilverFire, OndrejVasicek)
89
- Bug #13932: Fix number validator attributes comparison (uaoleg, s1lver)
910
- Bug #14039, #16636: Fixed validation for disabled inputs (s1lver, omzy83)

framework/assets/yii.validation.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,15 @@ yii.validation = (function ($) {
376376
return [];
377377
}
378378

379-
// Continue validation if file input does not exist
379+
var fileInput = $(attribute.input, attribute.$form).get(0);
380+
381+
// Skip validation if file input does not exist
380382
// (in case file inputs are added dynamically and no file input has been added to the form)
381-
if (typeof $(attribute.input, attribute.$form).get(0) === "undefined") {
383+
if (typeof fileInput === "undefined") {
382384
return [];
383385
}
384386

385-
var files = $(attribute.input, attribute.$form).get(0).files;
387+
var files = fileInput.files;
386388
if (!files) {
387389
messages.push(options.message);
388390
return [];

0 commit comments

Comments
 (0)