OpenForm

Logic

Last updated on

Named expressions and conditional logic

Logic types enable conditional behavior in forms and bundles. Named expressions can control field visibility, required status, and bundle content inclusion.

LogicSection

A mapping of named logic expressions that can be referenced throughout an artifact.

interface LogicSection {
  [key: string]: string
}

CondExpr

A conditional expression that can be used in include, required, and visible fields.

type CondExpr = boolean | string

When a string is provided, it can reference:

  • Named expressions from the logic section
  • Field values using fields.<fieldName>.value
  • Comparison operators (==, !=, >, <, >=, <=)
  • Logical operators (&&, ||, !)

Examples

kind: form
name: loan-application
logic:
  isEmployed: "fields.employmentStatus.value == 'employed'"
  needsCoSigner: "fields.creditScore.value < 650"
  showIncomeFields: "isEmployed"

fields:
  employmentStatus:
    type: enum
    label: Employment Status
    enum: ["employed", "self-employed", "unemployed", "retired"]

  creditScore:
    type: number
    label: Credit Score
    min: 300
    max: 850

  employer:
    type: text
    label: Employer Name
    visible: showIncomeFields
    required: showIncomeFields

  monthlyIncome:
    type: money
    label: Monthly Income
    visible: showIncomeFields
    required: showIncomeFields

  coSignerName:
    type: person
    label: Co-Signer
    visible: needsCoSigner
    required: needsCoSigner

Related

  • Form - Interactive form artifact
  • Bundle - Container artifact with conditional inclusion
  • FormField - Field definitions with conditional properties
  • FormAnnex - Attachment slots with conditional visibility and requirements

On this page