hamidrezahy / Blazor.QRCode

9 stars 1 forks source link

Clear method #4

Closed mikecasas closed 1 year ago

mikecasas commented 2 years ago

Thanks for the great control. When I use it in my app, I have a button and a textbox where users can enter their id number and it creates the QR code perfectly. If they enter multiple id's there are multiple QR codes down the page. Is there a way to clear the current QR code and then refresh it with the new text?

DannyRichardsonWG commented 1 year ago

I changed the js in qrcode-init.js to just grab the element and clear the contents before it regenerates the code


function initQrCode(elementId, text, width, height) {

    var ele = document.getElementById(elementId);
    if (ele != null) {
        ele.replaceChildren();
    }

    new QRCode(ele,
        {
            text: text,
            width: width,
            height: height
        });
}
mikecasas commented 1 year ago

@DannyRichardsonWG Thanks so much. It worked perfectly.