# Listening and clearing

* **Listening and clearing** These are mechanisms that make it possible to define the dynamic behavior of form components and the variables associated with them. Thanks to them, changes in one field can automatically affect other fields, components, or values in the form.
* **Listening attribute (ListeningOn)** – allows you to specify which other components or variables a given component “listens to”. This means that a change in the value of the specified component or variable will cause a reaction from the listening component – e.g. recalculation of its value or refresh of its visibility.
* **Field clearing attribute (ClearOn)** – defines which changes in other components or variables will trigger an automatic clearing (removal) of the value of a given component. In other words, if the indicated related field or variable changes its value, the component with clearing enabled will remove its own current value (clear the field).
* Both of the above attributes are available in the section **Interactions** of the selected component’s properties panel. Configuration is done using a special window – click the button **List** next to the field *Listening* or *Field clearing*, which will open a popup for editing these settings.

<figure><img src="/files/fc703e2bc58ad51e084b944fc356e6d7fe0b7213" alt=""><figcaption><p><em><strong>Figure 1.</strong> “Interactions” section</em></p></figcaption></figure>

* In the window **Change-triggering elements** (opened with the button **List**) a list of components that the given control listens to is displayed. The list can be narrowed using the filter field (**Filter...**) at the top of the window. Next to each added item there is a trash icon – it appears on hover – allowing you to remove that item from the list of listened-to elements.

<figure><img src="/files/0913ff785ae30602d02602e5dc67fb487073a7bf" alt=""><figcaption><p><em><strong>Figure 2.</strong> Window for selecting elements to listen to</em></p></figcaption></figure>

* To add a new element to listen to, use the field **Add MID** at the bottom of the window. This field suggests all available identifiers (MID/ID) of components and variables that can be listened to. Select the desired component from the suggestion list (by clicking it or confirming with the Enter key). The selected element will be added to the list, and the description of the Listening attribute in the properties panel will show information about the number of listened-to elements (e.g. *Listening: 1*).

<figure><img src="/files/3271cc515e9c9fa2b7095058cc195abdafc11abf" alt=""><figcaption><p><em><strong>Figure 3.</strong> Indicating an element to add</em></p></figcaption></figure>

* *Note:* If validators, services, or conditions (visibility, activity, requiredness) used in the component logic refer to values of other fields or variables, you should **properly set Listening (and possibly Field clearing)** for these dependencies. Otherwise, changes in the related fields will not be automatically taken into account by the given component.

### Usage examples

* **Automatic field recalculation** – A calculated field (e.g. the sum of two values) listens for changes in the source fields. If the user changes the value in one of the component fields, the sum field will automatically recalculate its value.
* **Dynamic section visibility** – A form section displayed conditionally (e.g. additional details shown after selecting the checkbox *“Show more”*) should listen to that checkbox. This way, changing the checkbox state will immediately cause the condition to be reevaluated and the section to be hidden or shown according to its definition.
* **Resetting the value of a dependent field** – A field that should be cleared after another selection changes uses the attribute *Field clearing*. For example, the field *“Car model”* can listen to the field *“Car make”* and have clearing set relative to it. Changing the make will automatically remove the previously selected model value so that the user selects a new model matching the changed make.
* **Refreshing the document list after changing the page** – The *Document List* component (DocumentList) can listen to the variable `currentPageMid` (identifier of the current form page). This causes the component to reload/refresh its data when moving to another page of the application. This avoids a situation where an outdated set of documents (e.g. printouts) is displayed after changing the page.

### FAQ

* **Q:** How do the attributes *Listening* and *Field clearing*?\
  **A:** *Listening* differ? *Field clearing* causes the component to react (recalculate or refresh) in response to a change in the value of a specified other field or variable. On the other hand,
* **Q:** Do I need to set listening if my component uses a condition or validator referring to another field?\
  **A:** Yes. If the component logic (e.g. visibility or requiredness condition, validator script, etc.) uses the value of another field or variable, then the component **must listen** to that element. Otherwise, changes in the value of that field will not be taken into account immediately – the condition or validation will not react to the changed data.
* **Q:** I set the attribute *Field clearing*, but the field does not clear its value when the related component changes – why?\
  **A:** Most likely the listening attribute is missing. For field clearing to work correctly, the target component must **also listen** to the indicated change-triggering element. In other words, in the component configuration you need to add *Listening* **together with** *Field clearing* referring to the same component whose change is supposed to clear the value.
* **Q:** How do I add or remove an element from the list of listened-to items for a given component?\
  **A:** You need to open the listening configuration window – in the properties panel click **List** next to the attribute *Listening*. In the window **Change-triggering elements** add a new element using the field **Add MID** (type or select the appropriate component/variable from the list and confirm with Enter). To remove an element from the listening list, simply hover over its name in this window and click the trash icon next to it.
* **Q:** What elements can be listened to?\
  **A:** A form component can listen to changes in **other components** (form fields) and to **session variables** associated with the form. During configuration in the listening window, a complete list of the ID/MID of all fields and variables that can be selected as listening sources is available.


---

# 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.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/formularze/dynamicznosc-formularza/nasluchiwanie-i-czyszczenie.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.
