Dynamic form elements using attributes
So far, we have only looked into changing forms depending on the user’s groups (the groups
attribute for elements and the groups_id
field for inherited views) and nothing more. This recipe will show you how to modify the form view based on the value of the fields in it.
How to do it...
- Define an attribute called
attributes
on a form element:<field name="child_ids" Â Â Â Â invisible="not parent_id" Â Â Â Â required="parent_id"/>
- Ensure that all the fields you refer to are available in your form:
<field name="parent_id"/>
This will make the child_ids
field invisible if the parent_id
is not hostel room category
, and it will be required if it’s a hostel room category.
How it works...
attributes contains a dictionary with invisible
, required
, and readonly
keys (all of which are optional). The values are domains that may refer to...