Creating dynamic forms

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

Basic 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 onchange event for 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 we select a contractor, the information about it will be displayed on the form in read-only mode. Note, that when we call For() method, we need to 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 for all time. To improve our form, we can only show them when a contractor is selected. To do that, we need to add a handler of 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);
When you create dynamic forms, you can only work with the variables that are added to the form.

See also: