How to change qr code filename while downloading the file using html.twig and javascript

I have a qr-code button. On click, qr-code is generated and dialog to save the image format pops-up. In which the filename always comes as “qrcode.png”. I have to dynamically change the filename to the name of the files from where the qr-code is generated.

Please, help. I am new to this technology.

HTML TWIG

<th data-field="QR-BTN" data-width="60px" data-orderable="false">{{ 'QR'|trans }}</th>

JAVASCRIPT

var QREXPORT = (function() {

var qrCodeExport = function (e){

    e.preventDefault();
    //goqr.me api url 
    const QRCODE_API_URL = "https://api.qrserver.com/v1/create-qr-code/?"; //Library Used

    var $form            = $('#modal-qr-export-offering'),
        qrFormat         = $("input[name='qrCodeType']:checked").val(),
        jsFormData       = $form.data('bs.modal'),
        accessCode       = jsFormData.options.accesscode;

    var params = {
                    data:     "SESSION-" + accessCode,
                    size:     "250x250",
                    margin:   0,
                    download: 1,
                    format:   qrFormat,
                 };

    window.location.href = QRCODE_API_URL + $.param(params); 

};

return {

    init: function() {

        $(document).ready(function(){

            $('#radioSvg').prop('checked', true);

            $('#modal-qr-export-offering').on('hidden.bs.modal', function() {
                location.reload();
            });

        });

        $(document).on('click', '.js-btn-submit-form', qrCodeExport);

    }
};

})();

QREXPORT.init();

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *