anseki / jquery-plainmodal

The simple jQuery Plugin for fully customizable modal windows.
http://anseki.github.io/jquery-plainmodal/
MIT License
78 stars 11 forks source link

Problem each time modal open, new same element created! #15

Closed codetinker closed 5 years ago

codetinker commented 5 years ago

Hi,

Thank you for creating great fully customize modal. Did not know this modal existed until today. However I found 1 issue.

Each time the modal is open, it will a duplicate of the same modal before. Thus making all the elements inside the modal duplicated as well. And this cause any script i wanted to do inside the modal is useless because of multiple element IDs existed.

This is the screenshot: https://imgur.com/cTXpaG5

I have created quick fixed for my solution: `

$('#loginSignUp').plainModal('open', { overlay: { fillColor: '#000', opacity: 0.8, zIndex: 99999 } });

// fixed duplicated same modal
var elms = document.querySelectorAll("[id='loginSignUp']");
if (elms.length > 1) {
  for (let i=0; i<elms.length-1; i++) {
    elms[i].remove();
  }
}

`

anseki commented 5 years ago

Hi @codetinker, thank you for your comment.

So, you have to reproduce a matter to inspect any problem. Also, I have to see your situation to help you. Could you reproduce that? For example, show me an example in: https://jsfiddle.net/

codetinker commented 5 years ago

Hi @anseki,

I've tried on https://jsfiddle.net/codetinker/1mjkvrqe/7/ using exactly same code and it work fine, no issue at all. It could be the problem only happen when I use plainmodal with angular 7.

So no issue then =) Thanks for helps

anseki commented 5 years ago

I see. The bug in your code creates new element every time when button was clicked. It seems that you wrote the code that creates new element in the event handler by mistake.

I'm glad if I could help you. :smile: