Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQueryUI - uncaught exception: cannot call methods

Tags:

jquery-ui

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.

like image 320
themerlinproject Avatar asked Sep 30 '10 04:09

themerlinproject


3 Answers

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.

like image 62
themerlinproject Avatar answered Nov 10 '22 02:11

themerlinproject


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");
like image 21
Josh Avatar answered Nov 10 '22 00:11

Josh


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"); }
like image 3
Hernaldo Gonzalez Avatar answered Nov 10 '22 01:11

Hernaldo Gonzalez