✔️ A friendly way to prompt your users for acknowledgement using Bootstrap modals.
To enable a modal to be used by acknowledge
, you need to have at least one button with a data-acknowledge
attribute.
Example:
<div class="modal fade" id="modal-one">
<div class="modal-dialog">
<div class="modal-content">
<button type="button" data-acknowledge="data-acknowledge">Continue</button>
</div>
</div>
</div>
Please do not put data-acknowledge
on the same button that also dismisses the modal - something disastrous could happen. acknowledge
will close the modal automatically upon acknowledgement, unless the keepOpen
option is passed.
With JavaScript, you can call acknowledge
by passing it a selector for the modal you want to target.
Using async/await:
import acknowledge from "acknowledge";
(async () => {
try {
await acknowledge("#modal-one");
} catch (err) {
console.warn(err);
}
})();
Using Promises:
import acknowledge from "acknowledge";
acknowledge("#modal-one")
.then(() => {
/* continue */
})
.catch(console.warn);
Because acknowledge
uses native Promises, if your target environment doesn't support Promises (like IE 11), make sure you include a polyfill.
Opens a modal. Returns a promise that resolves upon [data-acknowledge]
click, otherwise rejects if the modal is closed.
Type: String|DOMElement|jQuery
The target modal. Can be a selector (String), a DOMElement, or a jQuery object.
Type: Boolean
Default: false
Persists the user's acknowledgement. If true
and the user acknowledges a modal, acknowledge
will immediately resolve the next time it is called on that modal.
Type: String|DOMElement|jQuery
Default: document
Tells acknowledge
where to search for the target. Can be a selector (String), a DOMElement, or a jQuery object.
Type: Boolean
Default: false
Tells acknowledge
whether or not to keep the modal open after acknowledgement.
Type: Function
Default: noop
Execute a function before persisting the result or closing the modal in the event of an acknowledgement. The function can return a Promise. If the returned Promise rejects, or if the function throws an error, the acknowledgement will not complete. This is a good place to perform any extra validations on the modal.