CodeNewbie Community 🌱

Abdulrahman Noble
Abdulrahman Noble

Posted on

How to invoke dialog modal from module instead of using directly showModal() method

Good day! I need to have 2 different models to create projects and todo lists. I've figured out, that for html there is only one dialog menu that can be invoked with window.dialog.showModal(); directly. So then, I've created dialogModule file to store dialog model code for project pop-up model. Here is the code inside this module:

export const dialog = document.getElementById("project-dialog");
export const open = document.getElementById("open");
export const cancel = document.getElementById("cancel");
export const close = document.getElementById("close");


export let openModel = open.addEventListener("click", () => {
    dialog.showModal();
});

export let cancelModel = cancel.addEventListener("click", () => {
    dialog.close();
});

export let closeMondel = close.addEventListener("click", () => {
    dialog.close();
});
Enter fullscreen mode Exit fullscreen mode

And when I want to invoke project model menu, nothing happens.
Function that supposes invoking model:

import { dialog, open, openModel } from "./dialogModule";

function updateProjectItems(e) {
  openModel;
  const div = e.parentElement.parentElement.querySelector("div");
  projectValue.value = div.innerText;

  updateText = e.parentElement.parentElement.querySelector("div");
  addProjectUpdate.setAttribute("onclick", "UpdateOnSelectionProjects()");
  projectValue.focus();
}

Enter fullscreen mode Exit fullscreen mode

With updating todo list it has window.dialog.showModal();:

function UpdateToDoItems(e) {
    if (
      e.parentElement.parentElement.querySelector("div").style.textDecoration ===
      ""
    ) {
      window.dialog.showModal();
      const values = e.parentElement.parentElement.querySelectorAll("#values");
      todoValue.value = values[0].innerText;
      todoDescription.value = values[1].innerText;
      todoDate.value = values[2].innerText;
      todoPriority.value = values[3].innerText;


      updateText = e.parentElement.parentElement.querySelectorAll("#values");
      addUpdate.setAttribute("onclick", "UpdateOnSelectionItems()");
      todoValue.focus();
    }
}
Enter fullscreen mode Exit fullscreen mode

I use variable for projects to summon a pop-up menu, which is not working. What can I do to fix it?
Here is my full repo: github repo

Top comments (20)

Collapse
 
abbaskhan8008 profile image
Abbas Khan

we provide high-quality used auto spare parts in Sajaa, Sharjah, covering models from 2015 to 2024. Our parts are carefully inspected to ensure they meet the best standards, offering reliable performance for your vehicle. The sajaa used spare parts market in Sharjah is a popular place for finding affordable, high-quality spare parts for various car models.

Collapse
 
rabiamugal56 profile image
Rabia Mugal

Great question! Invoking a dialog modal from a module enhances code reusability and structure. Instead of calling showModal() directly, consider emitting an event or using a modal service to trigger it from the module. For a creative break while coding, Click Here to Read Shayari and refresh your mind with beautiful Hindi poetry.

Collapse
 
rabiamugal56 profile image
Rabia Mugal

That's a great question, especially for developers working with modular architectures. From a psychology Sunshine Coast perspective, it's interesting how user interface decisions—like invoking a dialog modal—can subtly impact user perception and interaction flow. Structuring modal logic within modules improves maintainability and aligns with how our brains favor clean, organized processes for smoother cognitive load handling.

Collapse
 
rabiamugal56 profile image
Rabia Mugal

If you're looking for fast and reliable lock services, a slotenmaker hoofddorp is the ideal solution. Whether you're locked out, need your locks replaced, or want to upgrade your home security, local locksmiths offer quick response times and expert advice. It's always reassuring to know that professional help is just around the corner when you need it most. Good security starts with strong, professionally installed locks—and a trusted locksmith makes all the difference.

Collapse
 
rabiamugal56 profile image
Rabia Mugal

I recently started reading Vagabond manga free online, and I’m honestly blown away. The art is absolutely stunning, and the story goes way deeper than just sword fights—it’s about growth, solitude, and the meaning of strength. Can’t believe such a masterpiece is accessible for free!

Collapse
 
rabiamugal56 profile image
Rabia Mugal

Itineraries are the backbone of any successful trip—whether you're planning a quick getaway or a month-long adventure, having a clear and flexible itinerary ensures you make the most of every moment. A well-crafted itinerary balances structure and spontaneity, giving you time to explore while staying on track.

Collapse
 
maicaljackson3 profile image
Maical Jackson

Exercise Physiotherapy is a game-changer for anyone looking to recover from injury, manage chronic conditions, or simply improve their physical health. With personalized movement plans and professional guidance, it empowers you to build strength, mobility, and confidence—one step at a time. A smart and sustainable path to long-term wellness!

Collapse
 
maicaljackson3 profile image
Maical Jackson

Looking for a trusted and efficient locksmith in the area? A slotenmaker Den Haag can provide fast and reliable services to ensure your property is secure. Don't settle for less when it comes to safety – choose the best!

Collapse
 
rabiamugal56 profile image
Rabia Mugal

Invoking a dialog modal from a module instead of using showModal directly is a great way to improve code structure and maintainability! Using a modular approach allows better reusability and flexibility in your application. While optimizing your development workflow, don’t forget to manage your expenses—use the iesco bill calculator to estimate your electricity costs and stay on budget!

Collapse
 
rabiamugal56 profile image
Rabia Mugal

Invoking a dialog modal from a module instead of directly using showModal() adds flexibility and reusability—just like customizing your strategy in nulls brawl apk! Modular code keeps things efficient, just as smart gameplay leads to victory.