mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 09:35:10 +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,
|
||||
onSessionRequestComplete: this.onSessionRequestComplete,
|
||||
onError: this.onError,
|
||||
onValidate: this.onValidate,
|
||||
onUploadChunk: this.onUploadChunk,
|
||||
onUploadChunkSuccess: this.onUploadChunkSuccess
|
||||
}
|
||||
@ -425,13 +424,17 @@ var ReactS3FineUploader = React.createClass({
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
},
|
||||
|
||||
onValidate(data) {
|
||||
if(data.size > this.props.validation.sizeLimit) {
|
||||
this.state.uploader.cancelAll();
|
||||
isFileValid(file) {
|
||||
if(file.size > this.props.validation.sizeLimit) {
|
||||
|
||||
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);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
@ -581,8 +584,18 @@ var ReactS3FineUploader = React.createClass({
|
||||
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
|
||||
if(this.props.uploadStarted && typeof this.props.uploadStarted === 'function') {
|
||||
if(this.props.uploadStarted && typeof this.props.uploadStarted === 'function' && files.length > 0) {
|
||||
this.props.uploadStarted();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user