# setFocus

Allows element focusing (set cursor to a field). The contents of the field can also be selected.

| Key       |         | Description                                           |
| --------- | ------- | ----------------------------------------------------- |
| action    | string  | setFocus                                              |
| elementId | string  | The DOM element that you want the focus to direct to. |
| select    | boolean | Field contents are selected when true                 |

## Example action object

```yaml
// action object for 'setFocus'
[
  {
    "action": "setFocus",
    "options": {
        "elementId": "name-first",
        "select": true
    }
  }
]
```

The `elementId` can be found by searching the HTML source code in the browser with an inspector tool. If you are setting focus to a BetterForms Element, the id is often set to the same as the `label` text but with lower case and hyphens for spaces.

Note:

The form must be rendered prior to this action being called. You may have to use a `wait` action to give the form a chance to render.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.klai.studio/v1/reference/actions-processor/actions_overview/setfocus.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
