Force a field to be mandatory in User Portal
Prerequisite: You must be familiar with the Syntax used in Tutorials and have already created an extension.
- learning:
- Force a field to be filled in User portal
- level:
- Intermediate
- domains:
- XML, Constrain, Portal
- min version:
- 2.1.0
This use case is just one way of forcing a field to be provided.
In this use case, we will describe how we have forced
service_id
and servicesubcategory_id
to
be mandatory on a UserRequest, when it is created in the User
Portal. As you can see in the Console, those 2 fields aren't
mandatory at UserRequets creation, because they are not mandatory
in the Datamodel and they are not mandatory within the lifecycle
before state 'Resolved'.
The User Portal is described in XML and you can change the
behavior and the look & feel of a form below the form
tag. Check reference for
exhaustive possibilities.
- itop_design / module_designs
-
<module_design id="itop-portal"> <forms> <form id="ticket-create"> <class>Ticket</class> <fields/> <!-- It's not possible to modify part of a twig without redefining it completely --> <twig _delta="redefine"> <div class="row"> <div class="col-sm-6"> <!-- data-field-flags can force a field to be mandatory, read_only, hidden --> <!-- or even to be modified (must_change). --> <!-- "mandatory,must_change" forces the field to be changed for a non-empty value --> <div class="form_field" data-field-id="service_id" data-field-flags="mandatory"></div> </div> <div class="col-sm-6"> <div class="form_field" data-field-id="servicesubcategory_id" data-field-flags="mandatory"> </div> </div> </div> <!-- [Rest of the XML tags for the twig...] --> </twig> </form> </forms> </module_design>
To remove the mandatory flag, redefine the twig with the existing XML in which you remove data-field-flags=“mandatory”.
Corner case: if a field is:
-
mandatory by Datamodel or mandatory due to the lifecycle flags
-
and is empty
-
and is specified as hidden or read_only or omitted in the Portal form
Then the Portal engine will ignore those form flags and will add the field as mandatory at the end of the form.