I’ve implimented the kitchen sink dialog modal and my issue is, no matter what, any button fires the code. I want the x button on top to close as well as a cancel button. I have 4 buttons in the dialog that will fire 4 different functions. However, clicking on any of the 4 buttons does nothing. it isn’t until you click either the x or the cancel button that fires the code.
What I need is to run the code for the button pressed and then close the dialog.
Here is my JS
// dialog handling
document.querySelector("#btnOpenDialog").onclick = () => {
document.querySelector("#dlgExample").uxpShowModal({
title: "Wood Ornament Options",
resize: "none", // "both", "horizontal", "vertical",
size: {
width: 480,
height: 440
}
});
};
// enable dialog buttons to close
Array.from(document.querySelectorAll("#dlgExample sp-button")).forEach(button => {
button.onclick = () => document.querySelector("#dlgExample").close();
});
function dialogTest(){
console.log("it worked");
}
document
.getElementById("orn-style1")
.addEventListener("click", function() {playAction('WoodOrnament-Style1')});
document
.getElementById("orn-style2")
.addEventListener("click", function() {playAction('WoodOrnament-Style2')});
document
.getElementById("orn-style3")
.addEventListener("click", ()=> {playAction('WoodOrnament-Style3')});
document
.getElementById("orn-style4")
.addEventListener("click", function() {playAction('WoodOrnament-Style4')});
and here is the HTML
<sp-action-button id="btnOpenDialog">Wood Ornaments</sp-action-button>
<dialog id="dlgExample">
<form method="dialog">
<sp-heading>Wood Ornaments</sp-heading>
<sp-divider size="large"></sp-divider>
<sp-body>Please Choose The Style You'd like to Mockup</sp-body>
<div class="ornament-styles">
<div id="orn-style1" class="orn-style"><img src="icons/ornament-style1.png" width="100px"></div>
<div id="orn-style2" class="orn-style"><img src="icons/ornament-style2.png" width="100px"></div>
<div id="orn-style3" class="orn-style"><img src="icons/ornament-style3.png" width="100px"></div>
<div id="orn-style4" class="orn-style"><img src="icons/ornament-style4.png" width="100px"></div>
</div>
<footer>
<sp-button id="button2" variant="cta">Cancel</sp-button>