admin管理员组文章数量:1323342
I am using plugin for image upload and I am stuck at Edit page since I have to set default image but unable to do so.I have to do it using jquery and ajax. I have tried attr() and setting data-defalut-file() but no success. Also when i use data-defalut-file() i can see my image in inspect element but not on UI. Please help :)
I tried :
$("#thumbnails_4_5").attr(
"data-default-file",
s3BaseUrlVideo +
"/" +
bucketName +
"/" +
images_folder +
"/" +
define_grid +
"/" +
horizontal +
"/" +
item.grid.thumbnail_4_5
);
and
$('.dropify').dropify({ defaultFile: nameImage , });
I am using https://github./JeremyFagis/dropify plugin for image upload and I am stuck at Edit page since I have to set default image but unable to do so.I have to do it using jquery and ajax. I have tried attr() and setting data-defalut-file() but no success. Also when i use data-defalut-file() i can see my image in inspect element but not on UI. Please help :)
I tried :
$("#thumbnails_4_5").attr(
"data-default-file",
s3BaseUrlVideo +
"/" +
bucketName +
"/" +
images_folder +
"/" +
define_grid +
"/" +
horizontal +
"/" +
item.grid.thumbnail_4_5
);
and
$('.dropify').dropify({ defaultFile: nameImage , });
Share Improve this question asked May 13, 2019 at 5:59 AKSHAY SALEKARAKSHAY SALEKAR 861 gold badge1 silver badge10 bronze badges3 Answers
Reset to default 4You cab use something like this(Using jQuery):
$('#input').attr("data-default-file", "imagePath");
$('#input').dropify():
Or you can set it directly
<input type="file" id="input" class="dropify" data-default-file="imagePath" />
Below code is solution for setting dynamic "data-default-file" on dropify.
// Define your new default image link
var newImageLink = 'https://upload.wikimedia/wikipedia/mons/1/13/Googlelogo_color_272x92dp.png';
// Get dropify instance
var myDropify = $("#yourDropifyInput").data('dropify');
// Reset current preview
myDropify.resetPreview();
myDropify.clearElement();
// Set new default file and re-init the dropify element
myDropify.settings.defaultFile = newImageLink;
myDropify.destroy();
myDropify.init();
If you want to update dropify image by JS or JQuery code, you need to remove the element and then append and initilize it again! something like this one :
$('#imageInput , .dropify-wrapper').remove();
html = `<input type="file" id="imageInput" class="dropify form-control" data-max-file-size="5M" id="imageInput" data-height="200" required=""
data-default-file='your_url' />`;
$('#imageInputContainer').append(html);
$('#imageInput').dropify();
本文标签: javascriptHow to set default image in dropify using jquery and ajax onlyStack Overflow
版权声明:本文标题:javascript - How to set default image in dropify using jquery and ajax only - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742134160a2422295.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论