How to call block loaded javascript function from a modal DHTML ?

How to call block loaded javascript function from a modal DHTML ?

by Alex Parsy -
Number of replies: 2
Hi,
I am on Moodle 1.9.1.

The general problem I am trying to solve is that when a link on a custom block is clicked, a modal DHTML window should popup and force the user to close it before they can continue.


I created a block with a link. When the link is clicked, a modal DHTML (Yahoo javascript library - lets call it myPanel modal window ) is poped up with all background disabled. Once the user closes the modal window, they can continue.

I am able to successfully inject the contents of my custom form (extends moodleform) into this modal DHTML window.

In my block code where my javascript was loaded, I have defined a custom javascript event that once the event is called, it closes myPanel.

What I want is that once the user clicks on the submit button of my DHTML displayed custom form, it calls the event that closes the myPanel.

My problem is that this event is not recognised while the DHTML modal window is up. I get a javascript error "myEvent" not recognised.

It seems the moodleform doesn't play well with my Javascript code that I loaded in my block. Do I have to navigate the DOM hierarchy to access the javascript code so I can call it ? I have no idea. Maybe I should totally forgoe using moodleform and just create my own form.

help!




Average of ratings: -
In reply to Alex Parsy

Re: How to call block loaded javascript function from a modal DHTML ?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I know Olli made this work in the new quiz editing interface in Moodle 2.0. So

1. Download and install Moodle 2.0
2. Create a course.
3. Add a quiz.
4. Make sure you are on the quiz 'Edit' tab.
5. Click the 'Add random question button' on the left and confirm it works.
6. Steal the code.

In reply to Tim Hunt

Re: How to call block loaded javascript function from a modal DHTML ?

by Alex Parsy -
thanks Tim for the tip. I'll check it out.