Skip to main content

Save bar API

The Save Bar API indicates that a form on the current page has unsaved information. You can implement save bar behavior in one of two ways:

  1. Automatic (form attribute): Add the data-save-bar attribute to a form element. The save bar displays automatically when there are unsaved changes. The submit event fires when the merchant clicks Save, and the reset event fires when the merchant clicks Discard. This is the simplest approach for standard form workflows.

  2. Programmatic (web component): Add a <ui-save-bar> element with a unique id to your page, then use shopify.saveBar.show(id), shopify.saveBar.hide(id), and shopify.saveBar.toggle(id) to control it. The <ui-save-bar> element can contain <button> children for Save (with variant="primary") and Discard. This approach gives you full control over when the save bar appears and what happens when merchants interact with it.

Caution

Choose one approach for each form. Don't combine data-save-bar on a form with programmatic shopify.saveBar methods — each approach manages save bar visibility independently and using both can cause unexpected behavior.

  • Standard forms: Use the data-save-bar attribute on a form element to automatically detect and manage unsaved changes with save and discard actions.
  • Custom state management: Use the <ui-save-bar> web component with shopify.saveBar methods to control the save bar based on application state that isn't tied to a single form.
  • Data protection: Prevent accidental data loss by prompting users when leaving a page with unsaved changes using shopify.saveBar.leaveConfirmation().

The saveBar object provides methods to programmatically control save bar visibility.

(id: string) => Promise<void>

Hides the save bar. Call this after the merchant saves or discards their changes.

Anchor to leaveConfirmation
leaveConfirmation
() => Promise<void>

Prompts the merchant to confirm before leaving the page when there are unsaved changes. The promise resolves when the merchant confirms or when no save bar is visible. Use this before programmatic navigation (for example, using window.location or custom routing) to prevent accidental data loss.

(id: string) => Promise<void>

Displays the save bar to indicate unsaved changes. Call this when you want to prompt the merchant to save.

Anchor to toggle
toggle
(id: string) => Promise<void>

Toggles save bar visibility between shown and hidden states.


Was this page helpful?