Skip to content
v0.9.1
Components

Confirm dialogs

"Delete 3 orders?" in one line. Momo.confirm(), Momo.alert() and Momo.prompt() show a Momo dialog and give you the answer, with no markup to write. Or put data-momo-confirm on a button, a link or a form and it asks before going ahead.

Ask before a click

Add data-momo-confirm with the explanation. The click, the link or the form only goes ahead after OK: your own handlers run then, not before.

Leave page
<div class="cluster">
  <button class="btn btn-red" type="button" id="cf-delete" data-momo-confirm="The orders and their invoices will be gone for good." data-confirm-title="Delete 3 orders?" data-confirm-ok="Delete orders" data-confirm-icon="trash-2"><i class="mi mi-trash-2"></i> Delete 3 orders</button>
  <a class="btn btn-ghost" href="#ask-before-a-click" id="cf-leave" data-momo-confirm="Your changes to this order are not saved yet." data-confirm-title="Leave this page?" data-confirm-ok="Leave" data-confirm-cancel="Stay"><i class="mi mi-log-out"></i> Leave page</a>
  <form id="cf-news" data-momo-confirm="1,248 customers will get this email right away." data-confirm-title="Send the newsletter?" data-confirm-ok="Send now" data-confirm-icon="send" data-confirm-color="violet">
    <button class="btn btn-brand" type="submit"><i class="mi mi-send"></i> Send newsletter</button>
  </form>
</div>
<script>
  (function () {
    document.getElementById('cf-delete').addEventListener('click', function () {
      Momo.toast({ title: '3 orders deleted', color: 'red', icon: 'trash-2' });
    });
    document.getElementById('cf-news').addEventListener('submit', function (e) {
      e.preventDefault();   // your form would really be sent here
      Momo.toast({ title: 'Newsletter sent', text: 'On its way to 1,248 customers.', color: 'green', icon: 'check' });
    });
  })();
</script>
<button class="btn btn-red" data-momo-confirm="The orders and their invoices will be gone for good."
  data-confirm-title="Delete 3 orders?" data-confirm-ok="Delete orders">Delete 3 orders</button>

<a href="/orders" data-momo-confirm="Your changes are not saved yet." data-confirm-ok="Leave" data-confirm-cancel="Stay">Leave page</a>

<form action="/newsletter" method="post" data-momo-confirm="1,248 customers will get this email right away.">…</form>

From code

Each one returns a promise: confirm gives true or false, prompt gives the text or null, alert finishes when it is closed.

Collection: Spring
<div class="cluster">
  <button class="btn" type="button" id="cf-archive"><i class="mi mi-archive"></i> Archive order</button>
  <button class="btn" type="button" id="cf-rename"><i class="mi mi-pencil"></i> Rename collection</button>
  <button class="btn" type="button" id="cf-alert"><i class="mi mi-info"></i> Show alert</button>
  <span class="text-sm text-muted">Collection: <b id="cf-name">Spring</b></span>
</div>
<script>
  (function () {
    document.getElementById('cf-archive').addEventListener('click', async function () {
      var yes = await Momo.confirm({ title: 'Archive order #10421?', message: 'You can find it later under Archived.', ok: 'Archive', icon: 'archive', color: 'yellow' });
      if (yes) Momo.toast({ title: 'Order #10421 archived', color: 'green', icon: 'check' });
    });
    document.getElementById('cf-rename').addEventListener('click', async function () {
      var out = document.getElementById('cf-name');
      var name = await Momo.prompt({ title: 'Rename collection', label: 'Name', value: out.textContent, required: true, maxlength: 30, ok: 'Rename', hint: 'Customers see this name in the shop.' });
      if (name !== null) out.textContent = name;
    });
    document.getElementById('cf-alert').addEventListener('click', function () {
      Momo.alert({ title: 'Import finished', message: '248 products were added. 3 were skipped because they had no price.', icon: 'circle-check', color: 'green', ok: 'Got it' });
    });
  })();
</script>
if (await Momo.confirm({ title: 'Archive order #10421?', message: 'You can find it later under Archived.', ok: 'Archive' })) {
  archive(10421);
}

const name = await Momo.prompt({ title: 'Rename collection', label: 'Name', value: 'Spring', required: true });
if (name !== null) rename(name);

await Momo.alert({ title: 'Import finished', message: '248 products were added.', icon: 'circle-check', color: 'green' });

// the short way
if (await Momo.confirm('Discard this draft?')) discard();

Good to know

Reference

Option / attributeWhat it does
title, data-confirm-titleThe question ("Are you sure?" by default)
message, data-momo-confirm="…"The explanation under it
ok, cancel, data-confirm-ok, data-confirm-cancelThe button words
danger: true, color, data-confirm-colorA red OK that starts on Cancel; any Momo color for the icon and the OK button
icon, data-confirm-iconA Moey icon beside the question (trash-2, archive)
label, value, placeholder, hint, type, required, pattern, maxlengthThe field of a prompt
Momo.confirm(), Momo.prompt(), Momo.alert()Promises: true / false, the text or null, nothing
Event momo:cancelOn the button, link or form when an attribute confirm is cancelled

Start

OverviewStart Getting startedStart CustomizeStart

Guides

AccessibilityGuides BreakpointsGuides ChangelogGuides Customize componentsGuides JavaScriptGuides MotionGuides OptimizeGuides PhonesGuides RebootGuides Right-to-left (RTL)Guides Stacking orderGuides Using Momo with AIGuides

Foundations

ColorsFoundations TypographyFoundations ProseFoundations Images & figuresFoundations CodeFoundations Lines & shadowsFoundations Dark modeFoundations

Forms

Checkbox & switchForms ComboboxForms Date pickerForms Date rangeForms Fields & labelsForms File uploadForms Floating labelsForms Number stepperForms PasswordForms PIN codeForms RatingForms SelectForms SliderForms Tag inputForms Time pickerForms ValidationForms

Components

AccordionComponents Alert & bannerComponents AvatarComponents BadgeComponents BreadcrumbComponents ButtonComponents Button groupComponents CalendarComponents CardComponents CarouselComponents ChartsComponents ChipsComponents CollapseComponents Command paletteComponents CommentsComponents Confirm dialogsComponents Cookie bannerComponents Data tableComponents Description listComponents Dialog & toastComponents DividerComponents DrawerComponents Dropdown menuComponents Empty stateComponents File managerComponents Filter & sortComponents Gallery & lightboxComponents Inbox & chatComponents Infinite scrollComponents KanbanComponents Keyboard shortcutsComponents List groupComponents MarqueeComponents Media objectComponents Nav overflowComponents Notification centerComponents PaginationComponents ProgressComponents Pull to refreshComponents SkeletonComponents SortableComponents SpinnerComponents Split viewComponents Stat cardComponents Steps & wizardComponents Swipe actionsComponents TableComponents TabsComponents TimelineComponents TogglerComponents Tooltip & popoverComponents TourComponents Tree viewComponents VideoComponents WhiteboardComponents

Layout

Announcement barLayout App shellLayout Back to topLayout Container & sectionLayout ExamplesLayout FooterLayout HeroLayout JumbotronLayout Mega menuLayout NavbarLayout Site sidebarLayout

Sections

Bento gridSections Blog cardsSections Call to actionSections Contact & newsletterSections FAQSections FeaturesSections Logo cloudSections PricingSections TeamSections TestimonialsSections

Utilities

OverviewUtilities State variantsUtilities Display & flexUtilities Grid & gapUtilities SpacingUtilities SizingUtilities TextUtilities Links & color strengthUtilities Position & overflowUtilities BackgroundsUtilities Borders & effectsUtilities Transforms & filtersUtilities InteractionsUtilities

Helpers

Fixed, sticky & frostedHelpers Hover & focusHelpers Hover revealHelpers Icon linkHelpers PrintHelpers Relative timeHelpers Screen reader textHelpers Scroll inHelpers ScrollspyHelpers Share buttonHelpers Skip linkHelpers StacksHelpers Stretched linkHelpers Theme toggleHelpers Truncated textHelpers

Page patterns

404 pagePage patterns Coming soonPage patterns Login & registerPage patterns SettingsPage patterns ProfilePage patterns CRM contactsPage patterns ProjectsPage patterns File manager pagePage patterns Billing & plansPage patterns Help centerPage patterns Mobile app screensPage patterns
↑ ↓ moveEnter openEsc close