Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Add code samples for confirm widget and added information about modalClass option #4732

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 82 additions & 1 deletion guides/v2.1/javascript-dev-guide/widgets/widget_confirm.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ For details about how to initialize a widget in a`.phtml` template, refer to the
- [content](#confirm_content)
- [focus](#confirm_focus)
- [title](#confirm_title)
- [modalClass](#confirm_modalClass)

### `actions` {#confirm_actions}
Widget callbacks.
Expand Down Expand Up @@ -110,18 +111,98 @@ The title of the confirmation window.

**Default value**: `''`

### `modalClass` {#confirm_modalClass}
The CSS class of the confirm window.

**Type**: String.

**Default value**: `'confirm'`

## Events {#confirm_events}

The confirmation widget implements the following events:

- `confirm` callback: called when the confirmation button is clicked.
- `cancel` callback: called when the cancel button is clicked.
- `always` callback.
- `always` callback: called when the popup is closed.

## Keyboard navigation {#confirm_key_navigation}

The keyboard navigation for the alert windows is similar to the [navigation of the modal widget].

## Code Sample

### Code sample of initialization on an element

```html
<div class="confirm-modal-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci amet aut consequuntur culpa cum, distinctio earum harum, iste magnam nobis numquam pariatur tempora ullam vero vitae. Hic ipsam itaque velit.</p>
</div>

<script>
require([
'jquery',
'Magento_Ui/js/modal/confirm'
], function ($) {
'use strict';

$('.confirm-modal-content').confirm({
title: 'Confirm Title',
modalClass: 'confirm',
actions: {
always: function() {
// do something when the modal is closed
},
confirm: function () {
// do something when the confirmation button is clicked
},
cancel: function () {
// do something when the cancel button is clicked
}
}
});
});
</script>
```

### Code sample of standalone initialization

```html
<div class="confirm-modal-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci amet aut consequuntur culpa cum, distinctio earum harum, iste magnam nobis numquam pariatur tempora ullam vero vitae. Hic ipsam itaque velit.</p>
</div>

<script>
require([
'jquery',
'Magento_Ui/js/modal/confirm'
], function ($, confirm) {
'use strict';

confirm({
title: 'Confirm Title',
content: $('.confirm-modal-content'),
modalClass: 'confirm',
actions: {
always: function() {
// do something when the modal is closed
},
confirm: function () {
// do something when the confirmation button is clicked
},
cancel: function () {
// do something when the cancel button is clicked
}
}
});
});
</script>
```

## Result

![Confirm Widget]({{ page.baseurl }}/javascript-dev-guide/widgets/images/confirm-widget-result.png)

[Magento modal widget]: {{page.baseurl}}/javascript-dev-guide/widgets/widget_modal.html
[`<Magento_Ui_module_dir>/view/base/web/js/modal/confirm.js`]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Ui/view/base/web/js/modal/confirm.js
[Magento Admin Pattern Library, the Slide-out Panels, Modal Windows, and Overlays topic.]: {{page.baseurl}}/pattern-library/containers/slideouts-modals-overlays/slideouts-modals-overalys.html#modals
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.