From cc7de3e86c5e07dc4015020ff575e5fb73f7f4cc Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Wed, 5 Jan 2022 19:45:05 +0800 Subject: [PATCH] MDL-73334 core: add CL documentation for core/confirm --- .../content/moodle/javascript/confirm.md | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 admin/tool/componentlibrary/content/moodle/javascript/confirm.md diff --git a/admin/tool/componentlibrary/content/moodle/javascript/confirm.md b/admin/tool/componentlibrary/content/moodle/javascript/confirm.md new file mode 100644 index 00000000000..458e76e9db7 --- /dev/null +++ b/admin/tool/componentlibrary/content/moodle/javascript/confirm.md @@ -0,0 +1,104 @@ +--- +layout: docs +title: "Confirm" +description: "A reusable confirmation modal component" +date: 2021-12-09T14:48:00+08:00 +draft: false +tags: +- MDL-71963 +- "4.0" +--- + +## How it works + +The confirm module is automatically invoked on page load, you just need to add some specific data attributes +to the element that will trigger the confirmation modal. + +## Source files + +* `lib/amd/src/confirm.js` +* `lib/templates/modal.mustache` + +## Usage +The confirmation AMD module is loaded automatically, so the only thing you need to do is to add some specific data attributes +to the target element: +{{< highlight html >}} + +{{< /highlight >}} + +You can also use it on PHP, you just need to set the attributes parameter to any moodle output component that takes attributes: +{{< php >}} +echo $OUTPUT->single_button('#', get_string('delete'), 'get', [ + 'data-confirmation' => 'modal', + 'data-confirmation-title-str' => json_encode(['delete', 'core']), + 'data-confirmation-question-str' => json_encode(['areyousure']), + 'data-confirmation-yes-button-str' => json_encode(['delete', 'core']) +]); +{{< / php >}} + +## Attributes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Data attributeDescription
data-confirmationThe identifier value must be "modal" so the module can find and register an event listener for that element.
data-confirmation-title-strThe modal title language string identifier, must be provided in JSON encoded format.
data-confirmation-question-strThe confirmation question language string identifier, must be provided in JSON encoded format.
data-confirmation-yes-button-strThe language string identifier for the "Yes" button, must be provided in JSON encoded format.
data-confirmation-toastIf set to "true" it will display a confirmation toast in the end.
data-confirmation-toast-confirmation-strThe confirmation toast language string identifier, must be provided in JSON encoded format.
data-confirmation-destinationAn url to redirect the user to.
+ +## Examples + +### Basic confirmation modal + +{{< example >}} + +{{< /example >}} + +### Confirmation modal with a toast + +{{< example >}} + +{{< /example >}} + +### Confirmation modal with redirect + +{{< example >}} + +{{< /example >}}