--- title: Save bar API description: >- 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. api_name: app-home source_url: html: >- https://shopify.dev/docs/api/app-home/apis/user-interface-and-interactions/save-bar-api md: >- https://shopify.dev/docs/api/app-home/apis/user-interface-and-interactions/save-bar-api.md --- # 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](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form). The save bar displays automatically when there are unsaved changes. The [`submit`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit_event) event fires when the merchant clicks **Save**, and the [`reset`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/reset_event) event fires when the merchant clicks **Discard**. This is the simplest approach for standard form workflows. 2. **Programmatic (web component)**: Add a `` 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 `` element can contain ` ); } ``` * #### ##### Description Toggle the save bar. This example defines a \`\\` element with an \`id\`, then uses \`shopify.saveBar.toggle(id)\` to switch between shown and hidden states. ##### tsx ```tsx function ToggleExample() { const saveBarId = 'toggle-save-bar'; const handleToggle = () => { shopify.saveBar.toggle(saveBarId); }; return ( Toggle save bar ); } ``` * #### ##### Description Leave confirmation. This example uses \`shopify.saveBar.leaveConfirmation()\` to prompt the merchant before programmatic navigation when there are unsaved changes. ##### tsx ```tsx function LeaveConfirmationExample() { const saveBarId = 'leave-confirm-save-bar'; const [hasUnsavedChanges, setHasUnsavedChanges] = React.useState(false); const handleFieldInput = () => { if (!hasUnsavedChanges) { setHasUnsavedChanges(true); shopify.saveBar.show(saveBarId); } }; const handleCustomNavigation = async () => { // Call leaveConfirmation before programmatic navigation await shopify.saveBar.leaveConfirmation(); // Navigation proceeds after merchant confirms or if no unsaved changes window.location.href = '/other-page'; }; return ( Go to other page ); } ``` ***