简体   繁体   English

单击按钮时,防止jquery ui打开第二个对话框

[英]Prevent jquery ui opening a second dialog box when clicking on a button

I have a leaflet map with 2 layers and when I'm clicking a button "save", it opens a dialog box with a form to send some informatons to my database. 我有一个2层的传单地图,当我点击“保存”按钮时,它会打开一个对话框,其中包含一个表单,可以将一些信息按钮发送到我的数据库。

When my first layer is selected and I'm clicking on my "save" button, it opens the dialog box corresponding to my first layer. 当我选择第一个图层并点击“保存”按钮时,它会打开与我的第一个图层对应的对话框。

But then, when my second layer is selected and I'm clicking on my "save" button, it opens the dialog box corresponding to my second layer, but also the form I've opened just before for my first layer. 但是,当我选择了第二层并点击了我的“保存”按钮时,它会打开与我的第二层相对应的对话框,还会打开我之前为第一层打开的表单。

So, is it possible prevent the opening of this form ? 那么,是否有可能阻止这种形式的开放? Because if I do a .dialog('close'), it on the form not corresponding, it works but we can see it opening and then closing, so that's not really good ! 因为如果我做一个.dialog('close'),它在形式上不对应,它可以工作,但我们可以看到它打开然后关闭,所以这不是很好!

I have already tested .dialog("destroy"); 我已经测试过.dialog(“destroy”); and .remove(); 和.remove(); but it removes my dialog boxes in the DOM and I can't open them other times after. 但它删除了我在DOM中的对话框,之后我无法打开它们。

So, here is some code : 所以,这里有一些代码:

 //Code in the oneachfeature function from my layer1 $('#save').on('click',function(e){ var dialog1 = $("#dialog1").dialog({ autoOpen: false, modal: true, show: { effect: "blind", duration: 500 }, hide: { effect: "blind", duration: 500 }, close: function(event, ui) { //$(this).dialog("destroy"); //$(this).dialog("close"); //$(this).remove(); }, height: 400, width: 500, modal: true, position: { my: "center center", at: "center center", of: "#map" }, buttons: { Valider: function() { // Ajax to send informations in the form }, // end of valider Annuler: function() { dialog1.dialog("close"); }, }, // end of buttons }); // end of dialog dialog1.dialog("open"); $("#dialog2").dialog('close'); }); // end of save //Code in the oneachfeature function from my layer2 $('#save').on('click',function(e){ var dialog2 = $("#dialog2").dialog({ autoOpen: false, modal: true, show: { effect: "blind", duration: 500 }, hide: { effect: "blind", duration: 500 }, close: function(event, ui) { //$(this).dialog("destroy"); //$(this).dialog("close"); //$(this).remove(); }, height: 400, width: 500, modal: true, position: { my: "center center", at: "center center", of: "#map" }, buttons: { Valider: function() { // Ajax to send informations in the form }, // end of valider Annuler: function() { dialog2.dialog("close"); }, }, // end of buttons }); // end of dialog dialog2.dialog("open"); $("#dialog1").dialog('close'); }); // end of save 

Your two save buttons, for each layer, seem to have the same id. 每个图层的两个保存按钮似乎具有相同的ID。 Maybe there is a conflict when you install your "onclick" listeners ? 安装“onclick”监听器时可能存在冲突? So the behavior is not what you expect. 所以行为不是你所期望的。 Try to set unique ids for these buttons 尝试为这些按钮设置唯一的ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM