This repository has been archived by the owner on May 25, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace deprecated Deferred.pipe() with .then()
- Loading branch information
Showing
2 changed files
with
8 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7489eb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this broke the file-validation when
jquery.fileupload-ui.js
together withtmpl.js
templates are used. the fileupload-ui'sadd
function is now called beforevalidate
, and thus any template-conditions that check for file errors will not match. when validate is finally called, the template has already been rendered and the expected error is not shown.simple example to reproduce:
acceptFileTypes: /\.png$/i,
unfortunately I have not found a solution for this regression - my current workaround is to replace
then
back topipe
which is obviously not a long-term fix.7489eb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@heldchen
The demo also makes use of client-side file validation and the tmpl.js rendering library and the validation works as expected.
Can you reproduce your reported issue with the demo?
7489eb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blueimp yeah, if you modify the upload template to actually use
{% if (file.error) { %}
- in our case, we are only showing the progress bar if there was no validation error. if you change the template code in your demo accordingly, you can reproduce the problem:the progress bar now should only be shown when the validation succeeded. try to upload a 10mb file now -error message and progress bar is show, because the template-
if
is evaluated before thevalidate
function was executed.7489eb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to get the file upload working for us I had to replace
then
withpipe
. If you do that there is another problem with the order of execution. Thevalidate
method will only be executed after the media methods (loadImageMetaData
,loadImage
,resizeImage
, etc.) have been executed. So, if you want a file upload that does not accept images, the template will be executed before thevalidate
method is called. So the user will never see the message "File type not allowed". Instead the progress bar (or whatever is defined in the template) is shown and nothing happens.The reason for this is straight forward. It has to do with the fact that the methods are not added to the
processQueue
array in the right order. Thevalidate
method is added with apush
, the media methods are added withunshift
.7489eb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@heldchen
The upload template has been rendered before the processing callbacks (which includes validation) for more than 3 years now (to allow canceling the processing queue via the user interface): cc70588
The UI library therefore updates the rendered rows again after processing (see e.g. here).
Of course this is only a sample implementation and you can implement a different rendering logic.
@ktruehl
Actually, the order of processing methods is exactly as it should be:
resizeImage
has to be executed before validation, as it changes the file size and potentially the image type, which are both metrics for validation.loadImage
has to be executed before resizing, as resizing requires the loaded image data.loadImageMetaData
has to be executed before resizing, as resizing also allows re-orientation, which usually makes use of EXIF orientation data.