You are browsing the documentation for iTop 2.7 which is not the current version.

Consider browsing to iTop 3.2 documentation

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.

This method can force a field to be provided in the Portal ONLY. It has no effect on all other creation/modification means.

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:

Then the Portal engine will ignore those form flags and will add the field as mandatory at the end of the form.

2_7_0/customization/mandatory-in-portal.txt · Last modified: 2020/04/15 15:23 by 127.0.0.1
Back to top
Contact us