# saveShortcut

> Why JS: a page has no key binding for submitting a form, so script binds ⌘S/Ctrl+S to the form a person is editing, in place of the browser's own save-page dialog.

```ts
import { saveShortcut } from "@sdxc/ui/app";
```

Applied to any element in or beside a form: ⌘S (Ctrl+S elsewhere) submits that form through
`requestSubmit`, while typing included. With several bound forms on a page, the one holding
focus saves; with focus outside them all, the only bound form saves.

## Signature

```ts
saveShortcut(options?: SaveShortcuts.Options): MixinDescriptor<HTMLElement>
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `options?` | `SaveShortcuts.Options` |  |

## Examples

```tsx
<span hidden mix={[saveShortcut({ form: "post-form" })]} />
```

## Used with it

The events, constants and types its module publishes, each imported from `@sdxc/ui/app` too.

### SAVE_SHORTCUT

The keys that save, as the shortcut registry spells them.

#### Signature

```ts
const SAVE_SHORTCUT = "mod+s"
```

### bindSaveShortcut

Binds ⌘S to `binding.form` until `signal` aborts, through the page's shortcut registry. Every
binding on the page agrees on one form per keystroke, so exactly one saves; a keystroke that
chooses none is still held back from the browser's save-page dialog.

#### Signature

```ts
bindSaveShortcut(binding: SaveShortcuts.Binding, signal: AbortSignal): void
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `binding` | `SaveShortcuts.Binding` | The form and how it saves. |
| `signal` | `AbortSignal` | Removes the binding. |

### SaveShortcuts.Options

Configuration for saveShortcut.

#### Members

| Member | Type | Description |
| --- | --- | --- |
| `form?` | `string` | The `id` of the form ⌘S submits; omit to submit the form the host sits in. |

### SaveShortcuts.Binding

One form's answer to ⌘S.

#### Members

| Member | Type | Description |
| --- | --- | --- |
| `form` | `HTMLFormElement` |  |
| `save` | `void` | Saves the form once ⌘S chose it. |
| `fallback?` | `boolean` | Yields to every other binding of the same form, so a save bar steps aside for the form's own primary save and one keystroke submits once. |
