Reputation: 29
I have a problem with jquery-ui.
I bind a click event to open a dialog, but the dialog's open function fires twice.
The click event only fires once, is only the open function that opens two dialog
This is my code:
<div id="modalWindow">Cargando...</div>
<script>
$(document).ready(function () {
var ventana = $("DIV#modalWindow");
ventana.dialog({
autoOpen: false,
show: "slow",
hide: "slow",
width: 500,
resizable: false,
draggable: false,
modal: true,
closeOnEscape: true,
Ok: function () { $(this).dialog("close").html("Cargando..."); },
close: function () { $(this).html("Cargando..."); }
});
$("DIV.imagen_perfil img").click(function (evt) {
//...some code
ventana.dialog({
title: "Subir Imagen",
open: function (event, ui) {
//...loads PartialView
}
});
ventana.dialog("open");
});
});
</script>
This is the HTML that fires the click event:
<li>
<label >Imagen de perfil:(Click en la Imagen Para Agregar):</label>
<div class="imagen_perfil">
<img src="~/images/imagen_pordefecto.png"/>
</div>
</li>
Upvotes: 0
Views: 1034
Reputation: 2159
It's because you are calling the dialog
function again in the click (which triggers the first open
call, the second is your actual call to open
), If you can ommit the dialog function, that solves the problem, if you really have to change information about the dialog, you should use the option
method (instead of calling dialog
again)
ventana.dialog( "option", { title: 'New Title',open:function(){...} } );
Upvotes: 3