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
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.
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" );
}
}
});
Please don't use this code - it will break your site.
Use this: https://docs.moodle.org/dev/AMD_Modal
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 ?
Dont use this: PAGE->requires->jquery() or any variation of it - that is for old Moodle plugins.
This page is useful to read before reading the one about the AMD modals: https://docs.moodle.org/dev/Javascript_Modules