0
0 Comments

I am working on a Django project where I use bootstrap.
I added this plugin https://plugins.krajee.com/file-input/plugin-options.
 
I have a modal where I use the file input, now is there any way to add file/files to the file input using an external button? (for example: I have a button to generate my Offer PDF, and when is generated I want to be auto added to my file input and be able to see it.
 
This is part of my HTML code:
 
“`
<div class=”form-group row hidden” id=”email_files_container_{{ action }}”>
    <div class=”col”>
        <input type=”file” component=”2″ file_type=”email” id=”id_email_files_{{ action }}” name=”email_files[]” class=”flow-files” multiple=”multiple”>
    </div>
</div>
<div class=”form-group row”>
    <button id=”id_file_pdf” type=”button” class=”btn btn-primary”>{% trans ‘Ataseaza Fisierul PDF’ %}</button>
</div>
“`
 
 
and this is part of my JavaScript Code:
 
“`
function AddFilePDF(myFileInput, object_type, object_id) {
$.ajax({
url: ‘/popup/get_email_pdf/’ + object_type + ‘/’ + object_id + ‘/’,
type: ‘GET’,
success: function(response) {
if (response.pdf) {
var pdf = response.pdf
 
const blob = new Blob([pdf.file], { type: pdf.file_mime });
                const newFile = new File([blob], pdf.file_name, { type: pdf.file_mime });
 
                myFileInput.fileinput(‘addToStack’, newFile);
 
}
},
error: function(xhr, status, error) {
console.error(‘Error:’, error);
}
});
}
“`
 
I tried this way and it is adding the file to the stack, but i cannot see it on my file manager.
 
 
 
I tried to add the files to the file manager stack, I tried then to refresh the input but with no success. I still can’t see the file on my file input.
[![This is my modal, when I press the “Adauga Fisierul PDF” button i want to add the generated file to my file input][1]][1]
 
 
  [1]: https://i.sstatic.net/JIrHk2C9.png

Is it posible to add a file using an external button in the file input?
Kartik V Changed status to publish June 27, 2024