I'm very new to jQuery and trying to run a pretty simple jQueryUI dialog box in my PHP application. In firebug console I get the error:
uncaught exception: cannot call methods on dialog prior to initialization; attempted to call method 'open'
Here is my code:
$(function() {
    $( "#dialog" ).dialog({
        autoOpen: false,
        show: "blind",
        hide: "explode"
    });
    $( "#opener" ).live('click',function() {
        $( "#dialog" ).dialog( "open" );
        return false;
    });
});
I did some googling on the error and not much turned up, except that jquery.ui.js is generating the error with:
if ( isMethodCall ) {
    this.each(function() {
        var instance = $.data( this, name );
        if ( !instance ) {
            throw "cannot call methods on " + name + " prior to initialization; " +
"attempted to call method '" + options + "'";
        }
...
Any ideas? I appreciate any help on what this error message is and how to resolve it.
UPDATE: I tried commenting out the show/hide options and that did not have any effect on my problem. Below is the HTML:
 <div class="demo">
    <div id="dialog" title="Basic dialog">
        <p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
    </div>
    <button id="opener">Open Dialog</button>
</div><!-- End demo -->
This HTML is included in a PHP file, which is INCLUDED in another PHP file.
OK, it had to do with the fact that I was putting the dialog DIV on a PHP file that hadn't been loaded yet at the time my JS was loaded. So I moved the DIV for the dialog box up to a higher page, and the button works on any page throughout my app now. I hope this helps someone else.
I was getting the same error. This fixed it for me, taken from http://forum.jquery.com/topic/jquery-ui-model-dialog-close
$(".ui-dialog-content").dialog().dialog("close");
In my case, I use: jQuery UI - v1.9.2, and I have only:
$this.sortable("destroy");
and I get:
Uncaught Error: cannot call methods on sortable prior to initialization; attempted to call method 'destroy'
And I fixed when add the validation:
if ($this.data( "ui-sortable" )) 
{ $this.sortable("destroy"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With