简体   繁体   中英

how to change default file dropify?

Hello

I am using Dropify.js, and I want to edit some items, so when I click to edit an item, the input with dropify class works fine it upload automatically the given file with this part of code:

  $('.dropify').dropify({
            defaultFile: app.getPath('userData') + '/images/' + doc.image
          });

but when I want to edit another item, the file doesn't change it still the first one. I hope you understund me. items are in a table. I found this but I dont know how to do it:

 var drDestroy = $('.dropify').dropify();
                drDestroy = drDestroy.data('dropify')
                $('#toggleDropify').on('click', function(e){
                    e.preventDefault();
                    if (drDestroy.isDropified()) {
                        drDestroy.destroy();
                    } else {
                        drDestroy.init();
                    }
                }) 

if any one can tell me what init() and destroy() and isDropified() functions do exaclty.

Here is a solution:

var imagenUrl = "";
var drEvent = $('#yourInputFileId').dropify(
{
  defaultFile: imagenUrl
});
drEvent = drEvent.data('dropify');
drEvent.resetPreview();
drEvent.clearElement();
drEvent.settings.defaultFile = imagenUrl;
drEvent.destroy();
drEvent.init();

For change dropify image src follow these line:

HTML:
<input type="file" id="image"  />
JS:
 $("#image").addClass('dropify');
 $("#image").attr("data-height", 300);
 $("#image").attr("data-default-file", "http://www.adamanthr.com/wp-content/uploads/2016/04/dummy-man-570x570.png");
 $('.dropify').dropify();

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