From bad0926ab111007ea877344ef716dd7894d031ef Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Wed, 3 Feb 2021 17:29:58 +0000 Subject: [PATCH] [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#68340 X-original-commit: 94c45412714c1263788b2567ce3c9581453b2cd4 Signed-off-by: Quentin Smetz (qsm) --- .../web_editor/static/src/js/wysiwyg/widgets/media.js | 11 ++++++++--- 1 file 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 8f7c6992450..9824e560535 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js @@ -557,13 +557,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.