Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing parameters to jquery ui dialog

I use .data like this to pass the id of the textbox that calls the dialog

$("#<%=txtDirProprio.ClientID%>").focus(function() 
{
         $("#<%=dialog.ClientID%>").dialog( "open" ).data("id","#<%=txtDirProprio.ClientID%>");
         return false;
});

here is the code for the dialog

 $("#<%=dialog.ClientID%>").dialog({
                autoOpen: false,
                show: "blind",
                hide: "explode",
                width: 800,
                height:200,
                modal: true,
                buttons: 
                {
                    "Ajouter": function() {
                        $( this ).dialog( "close" );
                        StringBuilderDir($( this ).data("id"));
                    },
                    "Vider": function() {
                        $( this ).dialog( "close" );
                        $( $( this ).data("id") ).val("")
                    },
                    "Canceler": function() {
                        $( this ).dialog( "close" );
                    }
                },
                open: function() 
                { 
                    var dir = $( $( this ).data("id") ).val().split("-");
                    if(dir[0] != "")
                    {
                        $("#<%=dd_dialog_directionvp.ClientID%> option").each(function(index) 
                        {
                            if ($("#<%=dd_dialog_directionvp.ClientID()%> option")[index].text == dir[0]) 
                            {
                                $("#<%=dd_dialog_directionvp.ClientID()%>  option")[index].selected = true;
                            }
                        })
                     }
                 }
                 });

So $ ( this ).data("id") returns the id of the textbox. It works fine except in the open function. The id is undefined

Why it works in the functions for the buttons but not in the open function. It looks like it's not the same 'this'

Thank you

like image 399
Marc Avatar asked Mar 02 '12 19:03

Marc


1 Answers

$("#<%=txtDirProprio.ClientID%>").focus(function() 
{
         $("#<%=dialog.ClientID%>").data("id","#<%=txtDirProprio.ClientID%>").dialog( "open" );
         return false;
});

Have to set the data first before calling .dialog('open');

like image 88
Brian Avatar answered Oct 22 '22 05:10

Brian