Skip to content

Solved multiple canvas issue#248

Open
TonyWhite wants to merge 1 commit into
davidshimjs:masterfrom
TonyWhite:patch-1
Open

Solved multiple canvas issue#248
TonyWhite wants to merge 1 commit into
davidshimjs:masterfrom
TonyWhite:patch-1

Conversation

@TonyWhite
Copy link
Copy Markdown

If el is already populate, it makes duplicate childs that can't fit in original geometry.
I added row 360 with this code to avoid the bug.
el.innerHTML = "";

Scenario for multiple canvas issue on Codepen
https://codepen.io/tonywhite1985/pen/bGgedMN?editors=1000

Try to comment this in JS tab on row 918
el.innerHTML = "";
and see glithes.

  1. Open RESULT tab and start typing some text to encode
  2. Detele all text
  3. Try to type another text to encode
  4. See qrcode (it shows badly when el.innerHTML = ""; is under comment)

If el is already populate, it makes duplicate childs that can't fit in original geometry.
I added row 360 with this code to avoid the bug.
el.innerHTML = "";

Scenario for multiple canvas issue on Codepen
https://codepen.io/tonywhite1985/pen/bGgedMN?editors=1000

Try to comment this in JS tab on row 918
el.innerHTML = "";
and see glithes.

1) Open RESULT tab and start typing some text to encode 
2) Detele all text
3) Try to type another text to encode
4) See qrcode (it shows badly when el.innerHTML = ""; is under comment)
@TonyWhite
Copy link
Copy Markdown
Author

I have improved the modularity of my scenario. Now, if you delete el.innerHTML = "", the glitch is immediately visible.

@markvantilburg
Copy link
Copy Markdown
Contributor

This would solve it for your use case without needing to changing the library.

Clear the element where the qr code is added before you call the method to add the qr code:

function createQRCode(textToEncode) {
document.getElementById("qrcode").innerHTML = '';
  qrcode = new QRCode(document.getElementById("qrcode"), {
    text: textToEncode,
    width: 300,
    height: 300,
    colorDark : "#000000",
    colorLight : "#ffffff",
    correctLevel : qrcodeQuality
  });
}

@TonyWhite
Copy link
Copy Markdown
Author

@markvantilburg it was my first step to solving the glitch. However the library adds a child without deleting or checking if another one already exists. I think it is useful to limit human errors by simplifying routine maintenance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants