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 attribute | +Description | +
---|---|
data-confirmation | +The identifier value must be "modal" so the module can find and register an event listener for that element. | +
data-confirmation-title-str | +The modal title language string identifier, must be provided in JSON encoded format. | +
data-confirmation-question-str | +The confirmation question language string identifier, must be provided in JSON encoded format. | +
data-confirmation-yes-button-str | +The language string identifier for the "Yes" button, must be provided in JSON encoded format. | +
data-confirmation-toast | +If set to "true" it will display a confirmation toast in the end. | +
data-confirmation-toast-confirmation-str | +The confirmation toast language string identifier, must be provided in JSON encoded format. | +
data-confirmation-destination | +An url to redirect the user to. | +