<commit_before>---
permalink: "pat/formautofocus/"
title: Formautofocus
---

# Formautofocus pattern.

## Configuration

|  Option   |  Type  |                     Default                     | Description |
| :-------: | :----: | :---------------------------------------------: | :---------: |
| condition | string |                   "div.error"                   |             |
|  target   | string | "div.error :input:not(.formTabs):visible:first" |             |
|  always   | string |      ":input:not(.formTabs):visible:first"      |             |<commit_msg>formautofocus add example<commit_after>---
permalink: "pat/formautofocus/"
title: Formautofocus
---

# Formautofocus pattern.

## Configuration

|  Option   |  Type  |                     Default                     | Description |
| :-------: | :----: | :---------------------------------------------: | :---------: |
| condition | string |                   "div.error"                   |             |
|  target   | string | "div.error :input:not(.formTabs):visible:first" |             |
|  always   | string |      ":input:not(.formTabs):visible:first"      |             |

## Examples

### Example 1

<h4>Form without Autofocus</h4>
<form>
  <div class="error">
    <input type="text" placeholder="should not be focused" name="in_other_form_should_not_be_focused" />
  </div>
</form>
<h4>Form with Autofocus</h4>
<form class="pat-formautofocus">
  <div>
    <input type="text" placeholder="should not be focused" name="a_should_not_be_focused" class="formTabs" />
    <input type="text" placeholder="should not be focused" name="b_should_not_be_focused" />
  </div>
  <div class="error">
    <input type="text" placeholder="should not be focused" name="c_should_not_be_focused" class="formTabs" />
    <input type="text" name="d_should_be_focused" />
  </div>
</form>

```html
<h4>Form without Autofocus</h4>
<form>
  <div class="error">
    <input type="text" placeholder="should not be focused" name="in_other_form_should_not_be_focused" />
  </div>
</form>
<h4>Form with Autofocus</h4>
<form class="pat-formautofocus">
  <div>
    <input type="text" placeholder="should not be focused" name="a_should_not_be_focused" class="formTabs" />
    <input type="text" placeholder="should not be focused" name="b_should_not_be_focused" />
  </div>
  <div class="error">
    <input type="text" placeholder="should not be focused" name="c_should_not_be_focused" class="formTabs" />
    <input type="text" name="d_should_be_focused" />
  </div>
</form>
```
{'fraction_non_alphanumeric': 0.20023790642347344, 'fraction_numerical': 0.0035685963521015066, 'mean_word_length': 2.3550531914893615, 'pattern_counts': {'":': 2, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '222867', 'n_tokens_mistral': 815, 'n_tokens_neox': 786, 'n_words': 154}