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 two ways:

  1. 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 Save button is pressed, and the reset event fires when the Discard button is pressed.

  2. Programmatic control: Use shopify.saveBar methods (show(), hide(), toggle(), leaveConfirmation()) to control the save bar based on your application state.

  • Form management: Automatically detect and manage unsaved form changes with save and discard actions.
  • Data protection: Prevent accidental data loss by prompting users when leaving a page with unsaved changes.
  • Programmatic control: Show, hide, and toggle the save bar programmatically for custom form workflows.
  • Form integration: Integrate with HTML form elements using the data-save-bar attribute for automatic change tracking.

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?