modal dialog

modal dialog

by sterk jim -
Number of replies: 5

Hi all,

I'am writing a custom page and want to know if

there is a way to show a modal dialog (for a delete confirmation)


thanks for your help

Average of ratings: -
In reply to sterk jim

Re: modal dialog

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes, there is. Lots of existing places in Moodle do that (typically when you try to delete something). Fine a place like that, then find the corresponding code.

In reply to Tim Hunt

Re: modal dialog

by sterk jim -
Hi Tim,


herewith my code 


if ($val->iduser == $USER->id) {

//  i need here a modal confirmation dialog 

                $DB->delete_records('block_linksh', $linkid);

                return true;

            }



I found some code with google , but  i don't know if it's fine to use with moodle


  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">  

  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>

  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>


    dialog = $( "#dialog-confirm" ).dialog({

      resizable: false,

      height: "auto",

      width: 400,

      modal: true,      

      buttons: {

        "Delete all items": function() {

          $( this ).dialog( "close" );

        },

        Cancel: function() {

          $( this ).dialog( "close" );

        }

      }

    });



In reply to sterk jim

Re: modal dialog

by Damyon Wiese -

Please don't use this code - it will break your site.


Use this: https://docs.moodle.org/dev/AMD_Modal

In reply to Damyon Wiese

Re: modal dialog

by sterk jim -
Hi thanks for your response,


can you explain me the step  to use  this AMD modal  ?


I have created a scritp.js file, it contians this  :


require(['jquery', 'core/modal_factory'], function($, ModalFactory) {

  var trigger = $('#create-modal');

  ModalFactory.create({

    title: 'test title',

    body: '<p>test body content</p>',

    footer: 'test footer content',

  }, trigger)

  .done(function(modal) {

    // Do what you want with your new modal.

  });

});



and in my page1.php i have this :


must i use this 

$PAGE->requires->jquery();

//$PAGE->requires->jquery_plugin('ui');

//$PAGE->requires->jquery_plugin('ui-css');


$PAGE->requires->js('/blocks/linksh/lib/scritp.js');


so now, how can a triger the modal windows ?