Hello,
Another newbie question from me I'm afraid....

I am including some javascript in my module:

drupal_add_js(drupal_get_path('module', 'mymodule') .'/myInclude.js');

And generally its all working fine...

However I'm now trying to add a dynamically generated modal dialog as per this example here:

http://jsfiddle.net/sje397/HRJBs/

So, my code would look like this:

(note: I've cut the code back to just what I am having trouble with)

(function ($) {
var diag = $('<div id="myDialog" title="Testing!"><span id="dialogMsg"></span></div>');

diag.dialog({
    autoOpen: false,
    modal: true
});

$('#diag1').click(function() {
    $('#dialogMsg').text("Message for dialog 1.");
    diag.dialog("open");
});

}(jQuery));

Now, when I try to run that code.. I get an error in the Chrome browser on the 'diag.dialog(' line as follows:

Uncaught TypeError: undefined is not a function

So, I'm wondering why this code works just fine in jsfiddle but not in Drupal.

I checked that it was ok with jQuery 1.4.4 ... and in jsfiddle the jQuery UI version is 1.8.5

I think it might be to do with the way you have to surround jquery code with the

(function ($) {
...
}(jQuery));

But I'm not sure what I have to do to fix it...
Any help would be greatly appreciated..

Vida

PS: can anyone tell me how to get these forms to email me to let me know there has been a reply to my post?

Comments

Jaypan’s picture

Uncaught TypeError: undefined is not a function

For what line of code?

nevets’s picture

First you want to read Managing JavaScript in Drupal 7, in particular the section titled "Behaviors" (this will cause you script to not run till the page is loaded)

Also, before your call to drupal_add_js() you need

drupal_add_library('system','ui.dialog');

As for your PS, not that I am aware of.

vidapura’s picture

Hi nevets,

Excellent, thats it. I didn't think I needed to include the ui.dialog library, thought it was automatically included like jquery is.

Apologies, I will go and read that link now.

Thanks again.

Vida.