Reusable - smbc-digital/form-builder GitHub Wiki

It's possible to build a library of consistent elements that can used in multiple forms. These use a special element called "Reusable".

Similar to a resuable lookup they allow to specify and reference element, this element will be substituted for the specified reusable elements when the form schema is loaded.

Reusable elements can contain references to lookups, so for example you could create a reusable element that specifies all the information surrounding a dropdown list (label, hint, validations etc.) but have the list content specified in the lookup.

It should be valid on all element types.

NOTE: Not all Element properties can currently be overridden within the Reusable element.

Current allowed values which can be overridden are:

  • Optional
  • Hint
  • CustomValidationMessage
  • TargetMapping
  • MaxLength
  • SummaryLabel (can be used in summary page and in submitandemail creation)
  • SetAutofocus

Properties

Property Type Required Default Value Description
ElementRef string ✔️ Reference to element
QuestionId string ✔️ Unique questionId

NOTE: When creating reusable Element do not specify a QuestionID or TargetMapping, this is done when consumed within the form schema using the reusable element.

NOTE: Optional should always be false and not set to true. This is due to a limitation that currently you can not override an optional element to be not optional. But you can do the reverse so always make Reusable elements none optional and you can override to be optional if required.

Reusable Element json example (email.json)

{
  "Type": "Textbox",
  "Properties": {
    "Label": "Email",
    "Email": true
  }
}

To use a reusable element, within the form json you put a Reusable element type with any properties you wish to override.

Example form with reusable element

{
   "ElementRef": "email",
   "Type": "Reusable",
   "Properties": {
      "QuestionId": "firstName"
   }
}