Trash Icon - Delete upload

Ask the community for help and support.
Post Reply
loop
VIP Member
VIP Member
Posts: 230
Joined: Thu Mar 25, 2021 12:26 pm
Has thanked: 7 times
Been thanked: 3 times

Trash Icon - Delete upload

Post by loop »

hi All
I'm stuck at the moment for (probably) e simple problem

i have added a custom file upload in categories.php
like this

Code: Select all

<div class="row mb-2" id="zPdf">
            <label for="pPdf" class="col-form-label col-sm-3 text-left text-sm-right">PDF Datenblatt</label>
            <div class="col">
              <div class="custom-file mb-2">
                <?php
                echo tep_draw_input_field('datasheet_pdf', '', 'id="pPdf"', 'file', null, 'class="custom-file-input"').'<label class="custom-file-label" for="pPdf">'.$product->get('datasheet_pdf').'</label>';
                ?>
              </div>
            </div>
            <div class="col-1"><a href="#" class="pdfDel"><i class="fas fa-trash text-danger"></i></a></div>
          </div>
everything work with the upload, but i try to make (same as image trash icon) so i can push the trash icon and the datasheet_pdf field is value change to empty

(and if this work, i want in the update /insert action to look if it's empty and if yes, i want to delete the old file)

But i can't get to work to empty the id="pPdf"
i tried document.getElementById("pPdf").html(''); but nothing changes...anybody a idea?
thank you!
ecartz
Lead Developer
Lead Developer
Posts: 2637
Joined: Tue Nov 05, 2019 6:02 pm
Has thanked: 4 times
Been thanked: 181 times

Re: Trash Icon - Delete upload

Post by ecartz »

Code: Select all

document.getElementById("pPdf").value = '';
loop
VIP Member
VIP Member
Posts: 230
Joined: Thu Mar 25, 2021 12:26 pm
Has thanked: 7 times
Been thanked: 3 times

Re: Trash Icon - Delete upload

Post by loop »

no, already tried that...gives no error, but also don't change value

i have done the same as on the images in the bottom
$(document).on('change', '#cPdf, [id^=pPdf]', function (event) { $(this).next('.custom-file-label').html(event.target.files[0].name); });

to fill the name....i have now made a workarround (but it's not really nice). whenn i hit trashbutton i change value of a hidden field named "delete_pdf" to 1 and thenn i look if it's 1 and if yes i delete it... really don't know why i can do it like you wrote ...
ecartz
Lead Developer
Lead Developer
Posts: 2637
Joined: Tue Nov 05, 2019 6:02 pm
Has thanked: 4 times
Been thanked: 181 times

Re: Trash Icon - Delete upload

Post by ecartz »

Post Reply