Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
Do we have any methods to prevent dialog box from appearing when the same dialog box is already opened?

I'm trying to fix the multiple dialog box appearing issue, where upon pressing fn key, dialog box appears to get input from user.Whenever i press fn key,the dialog box appears even when one of same dialog box is already opened.Then user needs to press cancel multiple times to close this dialog box. So i need to prevent this multiple dialog box from appearing when it is already opened.Condition to open dialog box is written in Js

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have not described specific dialog box you use, so I created a sample one and demonstrated the solution. What you should do it to implement a singleton design pattern, and Here is a sample Code I wrote in codepen. JS:

class singleModal{
  static isOpen=false;
  static id='dialog';
  static openModal(){    
    if(!singleModal.isOpen) {
      console.log("modal opened!")
      singleModal.isOpen = true;
      document.getElementById(singleModal.id).style.display='block';
    }
  }
  static closeModal(){    
    if(singleModal.isOpen) {
      console.log("modal closed!")
      singleModal.isOpen = false;
      document.getElementById(singleModal.id).style.display='none';
    }
  }
}


 singleModal.id = 'myDialog';
function openModal(){
singleModal.openModal();
}
function closeModal(){
singleModal.closeModal();
}
 

HTML:

<div class="dialog" id="myDialog">
  Dialog
</div>

<button onclick="openModal()">open</button>
<button onclick="closeModal()">close</button>

codepen

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!