Topic: File Upload Destory
martinmedina pro asked 5 years ago
I would like to reset the upload elements. If I clone the upload elements it dont work so I need to remove them and reset them.
martinmedina pro answered 4 years ago
For anyone needs this code to reset upload element.
$.fn.file_upload_destory = function() {
this.each(function (index, element) {
var name = $(this).attr('name');
var fileInput = '<input type="file" name="'+name+'" class="file_upload" data-height="80">'
$(this).closest(".file-upload-wrapper").parent().html('<div class="file-upload-wrapper">'+fileInput+'</div>')
}); };
How run.
$('.file_upload').file_upload_destory()
MDBootstrap staff answered 5 years ago
Hi martin,
this component does not support destroy method by default. You can accomplish that by restarting form that contains this element with code similar to this:
window.reset = function(e) {
e.wrap('<form>').closest('form').get(0).reset();
e.unwrap();
}
<form>
<input id="file" type="file">
<br>
<input id="text" type="text" value="Original">
</form>
<button onclick="reset($('#file'))">Reset file</button>
<button onclick="reset($('#text'))">Reset text</button>
If you need additional help I am here for you.
Best Regards, Piotr
martinmedina pro answered 5 years ago
I am using a modal with the upload element in the modal. The modal shows up when you hit edit on an item, I need to be able to reset the upload element. I want to know if there is a way destroy the upload box. Like the select $('.mdb-select').materialSelect({ destroy: true });
So Something like this. $('.file-upload').file_upload({ destroy: true });
Anna Morawska staff answered 5 years ago
Hi @martinmedina,
could you share with us your code? Do you use fileupload plugin or file upload jQuery component?
Best regards, Ania
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Pro
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.7.7
- Device: desktop
- Browser: chome
- OS: windows 10
- Provided sample code: No
- Provided link: No