logo

Creating dynamic forms

During ELMA implementation, you often need to create dynamic forms to satisfy the customer’s needs. In ELMA you create dynamic forms using handlers of onload or onchange events.

Standard use cases

The event handler in ELMA is a C# script. Below are few examples of event handlers:

  • Show/hide a form field;
  • Set a form field to read-only mode;
  • Set a form field to required mode;

Let’s see how you can create a dynamic form of a business process task. E.g. when you select a contractor, you need also display the information about it on the form.

To create a handler of an onchange event for the Contractor property, you need to create a new script:

The script code:

/// <summary>
        /// GetContractorInfo
        /// </summary>
        /// <param name="context">Process context</param>
        /// <param name="form"></param>
        public virtual void GetContractorInfo (Context context, EleWise.ELMA.Model.Views.FormViewBuilder<Context> form)
        {
            if (context.Contractor != null)
            {
                context.Industry = context.Contractor.Industry;
                context.RegionalGroup = context.Contractor.Region;
                context.SalesRep = context.Contractor.Responsible;
                
                form.For(c => c.Industry).ReadOnly(true);
                form.For(c => c.RegionalGroup).ReadOnly(true);
                form.For(c => c.SalesRep).ReadOnly(true);
            }
        }

Now, when you select a contractor, the information about it will be displayed on the form in read-only mode. Note, that when you call the For() method, you must pass a lambda expression to it to define the form field to work with.

Currently, the form fields Industry, Regional group and Sales rep are visible on the form always. To improve the form, you can only show them when a contractor is selected. To do that, you need to add a handler of the form onload event:

The script code:

public virtual void FormOnloadEvent (Context context, EleWise.ELMA.Model.Views.FormViewBuilder<Context> form)
        {
            if (context.Contractor == null)
            {
                form.For(c => c.Industry).Visible(false).Required(false);
                form.For(c => c.RegionalGroup).Visible(false).Required(false);
                form.For(c => c.SalesRep).Visible(false).Required(false);
            }
        }
Attention
When you create dynamic forms, you can only work with the variables that are added to the form.

See also: