# History

(history)

## Overview

The **History** object provides tools to manage a history stack, enabling navigation and manipulation of forms in the stack. It includes properties and methods to configure settings, navigate through history, and modify its content. ## Functionality

The primary property, `buttonsEnabled`, allows enabling or disabling history buttons, enhancing user interface control. It is a Boolean value that can be set or retrieved.

The object offers several methods for history stack management:

* Navigation methods like `back()`, `forward()`, and `go(i)` allow users to move through or jump to specific points in the history.
* Management methods such as `clear()` to reset the stack, `removeForm(formName)` and `removeIndex(index)` to delete specific entries, and `size()` to retrieve the stack's total size.
* Utility methods like `getCurrentIndex()` and `getFormName(i)` provide insights into the stack's state or retrieve specific form names based on their position.

These features ensure efficient and dynamic control over form navigation and history management.

## Properties Summarized

| Type                                                                           | Name                              | Summary                              |
| ------------------------------------------------------------------------------ | --------------------------------- | ------------------------------------ |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [buttonsEnabled](#buttonsenabled) | Set/Get the history buttons enabled. |

## Methods Summarized

| Type                                                                           | Name                                         | Summary                                                                                      |
| ------------------------------------------------------------------------------ | -------------------------------------------- | -------------------------------------------------------------------------------------------- |
| void                                                                           | [back()](#back)                              | Navigates back in the history stack; shows the previous form (if present).                   |
| void                                                                           | [clear()](#clear)                            | Clear the entire history stack.                                                              |
| void                                                                           | [forward()](#forward)                        | Navigates forward in the history stack; shows the next form (if present).                    |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [getCurrentIndex()](#getcurrentindex)        | Get the current absolute index in the history stack.                                         |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getFormName(i)](#getformname-i)             | Get the form name based on the specified absolute index in the history stack location.       |
| void                                                                           | [go(i)](#go-i)                               | Navigates to the relative index based on current position in the history.                    |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [removeForm(formName)](#removeform-formname) | Removes the named form item from the history stack (and from memory) if not currently shown. |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [removeIndex(index)](#removeindex-index)     | Removes an absolute index based history stack form item.                                     |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [size()](#size)                              | Returns the total size of the history stack.                                                 |

## Properties Detailed

### buttonsEnabled

Set/Get the history buttons enabled.

**Type**\
[Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) True if the history navigation buttons are enabled; otherwise, false.

**Sample**

```js
history.buttonsEnabled = true;
var status = history.buttonsEnabled;
```

## Methods Detailed

### back()

Navigates back in the history stack; shows the previous form (if present).

**Returns:** void

**Sample**

```js
history.back();
```

### clear()

Clear the entire history stack.

**Returns:** void

**Sample**

```js
history.clear();
```

### forward()

Navigates forward in the history stack; shows the next form (if present).

**Returns:** void

**Sample**

```js
history.forward();
```

### getCurrentIndex()

Get the current absolute index in the history stack.

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) the current absolute index

**Sample**

```js
var abs_index = history.getCurrentIndex();
```

### getFormName(i)

Get the form name based on the specified absolute index in the history stack location.

**Parameters**

* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **i** the absolute index

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the formName

**Sample**

```js
var name = history.getFormName(history.getCurrentIndex());
```

### go(i)

Navigates to the relative index based on current position in the history.

**Parameters**

* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **i** the relative index

**Returns:** void

**Sample**

```js
history.go(-3);
```

### removeForm(formName)

Removes the named form item from the history stack (and from memory) if not currently shown.\
Will return false when the form can't be removed, this can happen in certain situations:\
1> The form is visible,\
2> The form is executing a function (is actively used),\
3> There are references to this form by a global variable/array,\
4> If the form has a separate foundset with edited records that can't be saved (for example autosave is false)

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **formName** the name of the form to remove.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if successful

**Sample**

```js
var done = history.removeForm('mypreviousform');
```

### removeIndex(index)

Removes an absolute index based history stack form item.

**Parameters**

* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **index** the index of the form to remove.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if successful

**Sample**

```js
var done = history.removeIndex(history.getCurrentIndex()+1);
```

### size()

Returns the total size of the history stack.

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) the size

**Sample**

```js
var size = history.size();
```

***
