View elements also support a few dynamic attributes that allow views to dynamically change their appearance or behavior depending on field values . We may have on change events, able change values on other fields while editing data on a form, or have fields to be mandatory or visible only when certain conditions are met.

The on change mechanism also takes care of the automatic recomputation of computed fields, to immediately react to the user input. Using the same example as before, if the Price field is changed when we changed the Product, a computed Total Amount field would also be automatically updated using the new price information. Dynamic attributes A couple of attributes provide an easy way to control the visibility of a particular user interface element:

Other than these, we also have a flexible method available to set an element visibility depending on a client-side dynamically evaluated expression. This is the attrs special attribute, expecting for a value dictionary that maps the value of the invisible attribute to the result of an expression.

For example, to have the refers_to field visible in all states except draft, use the following code:

<field name="refers_to" attrs="{'invisible':   
  state=='draft'}" /> 

The invisible attribute is available in any element, not only fields. For example, we can use it on notebook pages and in group elements.

The attrs can also set values for two other attributes: readonly and required. These only make sense for data fields, to make them not editable or mandatory. This allows us to implement some basic client-side logic, such as making a field mandatory depending on other record values, such as the State.