diff options
| author | Romain Derie <rde@odoo.com> | 2021-02-03 17:29:58 +0000 |
|---|---|---|
| committer | Romain Derie <rde@odoo.com> | 2021-03-25 11:40:22 +0000 |
| commit | 27ac99ef87912c7ed926396d36aa159a4428b114 (patch) | |
| tree | 20aee1b4a95cc95ede63e456583657d8241fad1e | |
| parent | 4d529ad0d1b3e448fba7fb6cf54ed7991664f5aa (diff) | |
[FIX] web_editor: don't run code when input is emptied
Before this commit:
- Edit mode, open image dialog
- Upload an image to the media dialog
- Reclick on Upload but don't select an image, close the browser image
selector
- This will trigger the input change event, as the input was emptied
This is needed since in later commit, `_addData()` will do some code outside
of the `files` loop, which is useless if there is no files selected.
In thise case, the issue would be that it would open an empty toastr.
task-2345082
Coming from #65828
Closes #68326
closes odoo/odoo#68334
X-original-commit: 94c45412714c1263788b2567ce3c9581453b2cd4
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
| -rw-r--r-- | addons/web_editor/static/src/js/wysiwyg/widgets/media.js | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js index 9c7402f9722..703de4e744f 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js @@ -551,13 +551,18 @@ var FileWidget = SearchableMediaWidget.extend({ * @private * @returns {Promise} */ - _addData: function () { + async _addData() { + let files = this.$fileInput[0].files; + if (!files.length) { + // Case if the input is emptied, return resolved promise + return; + } + var self = this; var uploadMutex = new concurrency.Mutex(); // Upload the smallest file first to block the user the least possible. - var files = _.sortBy(this.$fileInput[0].files, 'size'); - + files = _.sortBy(files, 'size'); _.each(files, function (file) { // Upload one file at a time: no need to parallel as upload is // limited by bandwidth. |
