FineUploader: Add/change validation rules on onValidate/onValidateBatch callback

白昼怎懂夜的黑 提交于 2019-12-11 20:23:23

问题


On a page, a fineUploader dropzone is created with some initial validation settings. Before the user hits the Upload button, a few validation settings may change. How to make fineUploader to replace the initial validation rules with the new ones?

I have an application that allows you to create ads of different sizes and i want to use the qq.ImageValidation to validate the image ad dimensions.


回答1:


How to make fineUploader to replace the initial validation rules with the new ones?

You cannot. But you can call a function within the submit event which can dynamically validate files, and set some "base" validators in the validation option.

validation: {
// set default options such as making sure all uploads are images 
// or within a certain size.
},

onSubmit: function (id, name) {

   var file = this.getFile(id),
       validated = validate(file);
   if (validated) return true;
   else return false;
}

If this function returns false, then the item will not be marked as validated and not be uploaded. If this function returns true, then the validators you set in the options will be ran over the file(s) afterwards.



来源:https://stackoverflow.com/questions/20595950/fineuploader-add-change-validation-rules-on-onvalidate-onvalidatebatch-callback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!