简体   繁体   中英

How to Remove alert validation in JQuery Multifile

I am using jquery multifile upload plugin http://www.fyneworks.com/jquery/multifile can able to select document but when i tried to select wrong file it shows validation message as alert

You cannot select a .mp4 file. Try again...

instead of alert message how to show as validation text message ? also any possiblities to add "Required" validation for file using this plugin.

I see you posted the question also in the plugin's Github . While you wait for a reply from the creator(s). Here are two "hacky" options that you can go with:

  1. Modify a local version of the plugin and remove the alert() towards the end of the code:

     ... error:function(a){"undefined"!=typeof console&&console.log(a),alert(a)} ... 

    or replace it with the a function that will show the validation text message:

     ... error:function(a){"undefined"!=typeof console&&console.log(a),myFunction(a)} ... function myFunction(errorMessage) { // PLACE YOUR CODE HERE } 
  2. Stop the event propagation if the file fails : use the validation events provided by the plug-in to stop the execution of the alert (in particular the onFileInvalid event).

     $('#WithEvents').MultiFile({ max: 2, max_size: 100, accept: 'jpg', onFileInvalid: function (element, value, master_element, event) { // PLACE YOUR CODE HERE event.preventDefault(); return false; }, }); 

    Truly, this event.preventDefault() doesn't work as it should, but it creates an error that stops the execution of the alert (I know it's not the best solution, but it kind of works).

    Also, as part of the code that you run, you'll have to reset the value of the input to an empty file or the incorrect one will still be selected (something like $("#myInput").val("") .


About making the field as required, you don't have to make changes in the plugin or anything, just indicate that your field is required , then thanks to the magic of HTML5 and your browser, the trick will be done:

<input multiple type="file" id="WithEvents" required />

You can see an example working here: http://jsfiddle.net/8ma0vmxd/ (I copied the code of the plugin directly on the JS window so you can easily see where the alert() is towards the end).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM