mirror of
https://github.com/ascribe/onion.git
synced 2025-01-05 11:25:09 +01:00
fix validation method
This commit is contained in:
parent
07ae8cc9bb
commit
f54d7bb85c
@ -229,7 +229,6 @@ var ReactS3FineUploader = React.createClass({
|
|||||||
onDeleteComplete: this.onDeleteComplete,
|
onDeleteComplete: this.onDeleteComplete,
|
||||||
onSessionRequestComplete: this.onSessionRequestComplete,
|
onSessionRequestComplete: this.onSessionRequestComplete,
|
||||||
onError: this.onError,
|
onError: this.onError,
|
||||||
onValidate: this.onValidate,
|
|
||||||
onUploadChunk: this.onUploadChunk,
|
onUploadChunk: this.onUploadChunk,
|
||||||
onUploadChunkSuccess: this.onUploadChunkSuccess
|
onUploadChunkSuccess: this.onUploadChunkSuccess
|
||||||
}
|
}
|
||||||
@ -425,13 +424,17 @@ var ReactS3FineUploader = React.createClass({
|
|||||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
},
|
},
|
||||||
|
|
||||||
onValidate(data) {
|
isFileValid(file) {
|
||||||
if(data.size > this.props.validation.sizeLimit) {
|
if(file.size > this.props.validation.sizeLimit) {
|
||||||
this.state.uploader.cancelAll();
|
|
||||||
|
|
||||||
let fileSizeInMegaBytes = this.props.validation.sizeLimit / 1000000;
|
let fileSizeInMegaBytes = this.props.validation.sizeLimit / 1000000;
|
||||||
let notification = new GlobalNotificationModel(getLangText('Your file is bigger than ' + fileSizeInMegaBytes + 'MB.'), 'danger', 5000);
|
|
||||||
|
let notification = new GlobalNotificationModel(getLangText('A file you submitted is bigger than ' + fileSizeInMegaBytes + 'MB.'), 'danger', 5000);
|
||||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -581,8 +584,18 @@ var ReactS3FineUploader = React.createClass({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validate each submitted file if it fits the file size
|
||||||
|
let validFiles = [];
|
||||||
|
for(let i = 0; i < files.length; i++) {
|
||||||
|
if(this.isFileValid(files[i])) {
|
||||||
|
validFiles.push(files[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// override standard files list with only valid files
|
||||||
|
files = validFiles;
|
||||||
|
|
||||||
// Call this method to signal the outside component that an upload is in progress
|
// Call this method to signal the outside component that an upload is in progress
|
||||||
if(this.props.uploadStarted && typeof this.props.uploadStarted === 'function') {
|
if(this.props.uploadStarted && typeof this.props.uploadStarted === 'function' && files.length > 0) {
|
||||||
this.props.uploadStarted();
|
this.props.uploadStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user