Autosave

autosave#

Type: false | object

Default: false

Pass an object with at least url or handler to enable autosave. An empty object or false keeps it off.

const app = Redactor('#entry', {
  autosave: {
    url: '/api/save',
    method: 'POST',
    name: 'content',
    debounce: 1000,
    data: {
      id: 42
    }
  }
});

url

Type: string

Endpoint for the save request. Uses the shared transport service (fetch). Required unless you use handler.

method

Type: string

Default: 'POST'

HTTP method. For GET, payload fields are appended as a query string.

name

Type: string

Default: the source element name, then id, then content-{uuid}

Field name for the editor HTML in the request body. The payload is { [name]: html, ...data }.

data

Type: object

Extra fields merged into the payload. Useful for record IDs, CSRF tokens, or other metadata.

debounce

Type: number

Default: 1000

Delay in milliseconds after the last editor:change before sending. Set to 0 or a non-positive value to save on every change without debouncing.

interval

Type: number

Optional interval in milliseconds for periodic saves (setInterval). Runs in addition to debounced saves on change.

handler

Type: (ctx) => any

Custom save function instead of url. Receives { app, name, data } where data[name] is the current HTML. Return any value; it is passed to success handling as response.

const app = Redactor('#entry', {
  autosave: {
    name: 'body',
    debounce: 1500,
    handler({ name, data }) {
      return fetch('/api/save', {
        method: 'PUT',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(data)
      });
    }
  }
});

Request format#

POST requests send application/x-www-form-urlencoded data by default:

content=<p>Hello</p>&id=42

Use handler when you need JSON, FormData, or another format.