Marc
Marc

Reputation: 16512

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

Upvotes: 5

Views: 21255

Answers (1)

Brian
Brian

Reputation: 3023

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

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

Upvotes: 9

Related Questions