1. Home
  2. Administrators
  3. Data fields
  4. How to run a script when you change the value of a field in the edit screen

How to run a script when you change the value of a field in the edit screen

Users enter or modify the value of data fields in Docuo from the details window of a document, or from web forms.

To facilitate data entry, when a field is created, the type of content it will have is configured: Date, number, currency, text, drop-down lists, etc.

However, sometimes, it is necessary to carry out a stricter control of what users can enter in a field.

Restricting the format of a field by means of a regular expression

A first option is to set a Format, a strict restriction on what a user can enter, configured from what are known as regular expressions.

A regular expression is a sequence of characters that allows to detect a certain input pattern in a text. Information on how to define regular expressions to validate text can be found at http://www.regular-expressions.info/.

Use the “Behavior – Format” option to set up a regular expression in a field to validate what the user enters:

However, in some scenarios, rather than restricting what the user enters, what needs to be done is to analyze and modify it, either in the same field or in other fields.

Execute a Script when a user changes the value of a field

The event “When changing the value” of the options of a data field, allows to write a code fragment in JavaScript language, which will be executed in the editing screen (details window or form) when the user types the text and validates it, typically by leaving the focus of the control (by pressing the tab key for example or clicking elsewhere with the mouse).

The JavaScript code you write here can use proprietary functions such as uiSetFieldValue, which allow you to MODIFY the contents of the field you are typing in, or even other fields:

This allows, for example, setting the first letter to uppercase when the user enters a proper name, parsing, splitting and separating the entered information and taking it to different fields, or simply validating the composition of what the user types with JavaScript and returning an explanatory error message.

Scripts entered in this event are limited to acting on the document window itself, they cannot perform functions that require calculations on the Docuo server or on other documents and categories.

Updated on 19 de December de 2023
Was this article helpful?

Related Articles