> ## Documentation Index
> Fetch the complete documentation index at: https://docs.clickterm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Events & callbacks

> Handle SDK events like acceptance, decline, and errors using Promise-based callbacks.

The ClickTerm Web SDK uses **Promises** to communicate results. The `show()` and `showAcceptedContent()` methods return promises that resolve on success and reject on error.

## Show result

When `ClicktermDialog.show()` resolves:

```javascript theme={null}
ClicktermDialog.show({
  endUserId: "user-123",
  clickwrapTemplateId: "YOUR_TEMPLATE_ID",
}).then((result) => {
  // result.clicktermSignature — the Signature to send to your backend
  console.log("Signature:", result.clicktermSignature);
}).catch((error) => {
  // SDK or network error
  console.error("Error:", error);
});
```

### Possible outcomes

| Outcome               | What happens                                                        |
| --------------------- | ------------------------------------------------------------------- |
| User accepts          | Promise resolves with a Signature — send it to your backend         |
| User declines         | Promise resolves with a Signature — verify it to record the decline |
| User already accepted | Promise resolves with `null` Signature — no dialog was shown        |
| Error                 | Promise rejects with an error message                               |

<Note>
  A `null` Signature means the user has already accepted the latest major version.
  No action is needed on your part.
</Note>

## Error handling

Errors are returned via the Promise `.catch()` handler:

```javascript theme={null}
ClicktermDialog.show({
  endUserId: "user-123",
  clickwrapTemplateId: "YOUR_TEMPLATE_ID",
}).catch((error) => {
  // Handle error — e.g., SDK not initialized, network issue, template not found
  console.error("Clickwrap error:", error);
});
```

Common error scenarios:

| Error               | Cause                                            |
| ------------------- | ------------------------------------------------ |
| SDK not initialized | `ClicktermClient.initialize()` was not called    |
| Template not found  | Template is disabled or has no effective version |
| Network error       | Cannot reach the ClickTerm API                   |

## Using async/await

<CodeGroup>
  ```javascript example.js (JavaScript) theme={null}
  try {
    const result = await ClicktermDialog.show({
      endUserId: "user-123",
      clickwrapTemplateId: "YOUR_TEMPLATE_ID",
    });

    if (result.clicktermSignature) {
      // Send to backend for verification
      await verifySignature(result.clicktermSignature);
    } else {
      // User already accepted — no action needed
    }
  } catch (error) {
    console.error("Clickwrap error:", error);
  }
  ```

  ```typescript example.ts (TypeScript) theme={null}
  interface ClickwrapResult {
    signature: string | null;
  }

  try {
    const result: ClickwrapResult = await ClicktermDialog.show({
      endUserId: "user-123",
      clickwrapTemplateId: "YOUR_TEMPLATE_ID",
    });

    if (result.clicktermSignature) {
      await verifySignature(result.clicktermSignature);
    } else {
      // User already accepted — no action needed
    }
  } catch (error: unknown) {
    console.error("Clickwrap error:", error);
  }
  ```
</CodeGroup>

***

## Inline mode callbacks

Inline mode uses a different callback pattern. Instead of a single Promise from `show()`, you get:

* **`onChange` callback** — fires every time the checkbox state changes (passed via options to `renderInline()`)
* **`finalize()` Promise** — resolves when the agreement is submitted to the backend

```javascript theme={null}
const handle = await ClicktermDom.renderInline('container', request, {
  onChange: (checked) => {
    // React to checkbox state changes
    submitButton.disabled = !checked;
  },
});

// Later, when the user submits your form:
const result = await handle.finalize();
if (result.status === 'ERROR') {
  console.error('Finalize failed:', result.error?.message);
}
```

For full details, see the [ClicktermDom API reference](/dev/sdk/web/clickterm-dom).
