Malcolm
Malcolm

Reputation: 12874

JQueryUI Calling Open on dialog on working

I am loading some html using JQuery .load and then using JQuery UI to open a dialog from a div in the loaded html. But it is not working and seems to be because the JQuery UI is not recognising the div exists although its loaded dynamically.

Do I have to do a .live or .on call somehow???

EDIT: Just realised divtimesheet is named twice so have changed one of them to divtimesheet_holder but still same problem?

   loadTimesheet = function () {
        var wkending =  getWeekEnding();
        var proId = $("#newtimesheet").attr("proid");
        $("#divtimesheet_holder").load("Timesheet/NewTimesheet", { proId: proId, enddate: "15/10/2014" }, function() { open();});
    }

   function open() {
        $("#clipboarddialog").dialog("open");
    }


<div id="clipboarddialog">
    <div id="clipboard">
        <div id="divtimesheet">
            @Html.Partial("Timesheet/TimesheetHeader", Model)
            @Html.Partial("Timesheet/TimesheetBody", Model)
            @Html.Partial("Timesheet/TimesheetFooter", Model)
        </div>
    </div>
</div>

Upvotes: 0

Views: 32

Answers (2)

Karthik Chintala
Karthik Chintala

Reputation: 5545

There are two ways of opening the dialog in jQuery.

First, you can directly open the dialog without mentioning any options for .dialog method.

$("#clipboarddialog").dialog();

Second, you initialize the dialog and open the dialog anywhere

//set up options
$("#clipboarddialog").dialog({options});

//open
$("#clipboarddialog").dialog("open");

In your case, you should not provide any options to the .dialog

Simply call it this way

function open() {
    $("#clipboarddialog").dialog();
}

Check this fiddle

Hope this helps

Upvotes: 0

Barmar
Barmar

Reputation: 782407

You need to call $("#clipboarddialog").dialog({ options }); to initialize the widget.

$(document).ready(function() {
    $("#clipboarddialog").dialog({ 
        autoOpen: false
    });
});

Upvotes: 1

Related Questions