Moey extras
Confirm dialogs
"Delete 3 orders?" in one line. Moey.confirm(), Moey.alert() and Moey.prompt() show a Moey dialog and give you the answer — no markup to write. Or put data-moey-confirm on a button, link or form and it asks before going ahead.
<button class="btn btn-red" data-moey-confirm="This can't be undone." data-moey-confirm-title="Delete 3 orders?" data-moey-confirm-ok="Delete orders">Delete 3 orders</button>
<a href="/orders" data-moey-confirm="You'll leave without saving.">Leave page</a>
<form data-moey-confirm="Customers will be emailed right away.">…</form>
- The click (or the form, or the link) only goes ahead after "OK" — your own
onclickand form handlers run then, not before. - A red button asks with a red OK, and starts on Cancel, so a stray Enter can't delete anything.
- Esc means Cancel. It's a real dialog: focus stays inside, screen readers announce it, and on phones it's a bottom sheet.
From code
Each returns a promise: confirm → true / false, prompt → the text or null, alert → when it's closed.
if (await Moey.confirm({ title: 'Archive order #10421?', message: 'You can find it later under Archived.', ok: 'Archive' })) {
archive(10421);
}
const name = await Moey.prompt({ title: 'Rename collection', label: 'Name', value: 'Spring', required: true });
if (name !== null) rename(name);
await Moey.alert({ title: 'Import finished', message: '248 products were added.', icon: 'circle-check', color: 'green' });
| Option / attribute | What it does |
|---|---|
title · data-moey-confirm-title | The question ("Are you sure?" by default) |
message · data-moey-confirm="…" | The explanation under it |
ok · cancel · data-moey-confirm-ok / -cancel | Button labels |
color · data-moey-confirm-color | The OK button's color (a red .btn-red button asks in red by itself); danger: true = red |
icon · data-moey-confirm-icon | An icon on top, in the same color |
label · value · placeholder · type · required · pattern | The field of a prompt |