MaestroThe UI design product. | Form Builder | All versions This feature is related to all versions.
An item encapsulates static data captured in Maestro about a form element, as well as providing methods for getting and setting data and checking the visible state of the HTML object that is created by Maestro from the item.
There is a one-to-one relationship between Maestro form elements and item objects at form runtime.
An item can be obtained in one of four ways:
Form.items
object has properties keyed on the Maestro ID. For instance, Form.items.firstName
is the item definition for the firstName
element.maestro.Form.items
, for example, maestro.Form.items.firstName
.Form.getItemFromPath(id)
API method. For example, if the item ID is only available as a variable:
let itemId = "firstName";
Form.getItemFromPath( itemId );
The Form
property is always available in the scope of any Maestro rule and outside of that the maestro.Form
property provides access to the same object from any scope.
Stylistically, Form.items.firstName
, which is the dot notation property accessor, is preferred to the API call Form.getItemFromPath("firstName")
. The dot property accessor approach is clearer, less brittle (Maestro can do a better job of refactoring elements when the ID is changed) as well as being more performant at runtime.
Rule developers don't need to look up the item on which the rule was invoked - it is passed as the second argument to the function body of every rule:
function(data, item, info) { // Your rule body... }
Developers working in Maestro don't code the function scaffold but simply reference these elements directly in the rule body. Therefore, the argument order is only important for developers who work with exported JavaScript code within an IDE.
The value returned by item.getData()
is the same as data.firstName
. Maestro even scaffolds the return statement, limiting the coding overhead even further. Consider the following two code snippets of a validation rule for an item:
item.getData().length > 25
The alternative approach is to use the data dot notation lookup as follows:
data.firstName.length > 25
The use of the item argument is more resilient to ID changes during refactoring, but arguably, the code is slightly less comprehensible. For more information, see data object.
As we have seen, using the item argument passed to a rule provides a consistent way to get and set data that is guaranteed to be robust if the ID of the element changes. Maestro Form API functions typically accept either a String identifier or an item object as arguments. In most cases, using item objects as function arguments is more robust.
For example, assuming the code is in a rule for the firstName
element, then instead of
Form.addRepeatInstance("firstName", repeatData);
the item can be substituted:
Form.addRepeatInstance(item, repeatData);
or:
Form.cacheData(item, dataToCache)
Form.clearValidationErrors(item)
Form.getBlockData(Form.items.lastName)
// and so on…
An Item object contains static data describing a single Maestro element as well as providing functions to get and set the data value bound to the element, and to query whether the item is enabled. The snippet below shows a browser inspecting an item that was passed as an argument to a rule:
Key properties of the item object include:
firstName
. As noted above, this ID is also used as a key in the Form.items
object meaning that this item could be found using Form.items.firstName
.maxLength
input constraint by changing this property.
Next, learn about an info object.