Expressions
Create computed fields and conditional logic with JEXL expressions in Crove templates.
Expressions
Expressions let you create computed fields and conditional logic in your templates using JEXL (JavaScript Expression Language). They evaluate automatically when form data changes.
Expression types
Computed fields
Computed expressions calculate a value from other variables. The result is displayed in the document and optionally in the form.
Examples:
// Calculate total from quantity and price
quantity * unitPrice
// Calculate tax (20%)
subtotal * 0.2
// Grand total
subtotal + tax
// Concatenate strings
firstName + " " + lastName
// Conditional text
contractType == "Annual" ? "12 months" : "Month-to-month"Conditions
Condition expressions evaluate to true or false. They control visibility of form fields and document sections.
Examples:
// Show field when account type is Business
accountType == "Business"
// Show discount section when amount exceeds threshold
orderTotal > 1000
// Show international fields when country is not US
country != "United States"
// Combine conditions
age >= 18 && hasConsent == trueCreating an expression
- Open the template editor
- Go to the Variables panel
- Click Add Expression
- Enter a name (e.g., "Total Amount")
- Choose the type: Computed or Condition
- Write the JEXL expression
- The expression is evaluated in real-time as form data changes
JEXL syntax reference
Operators
| Operator | Description | Example |
|---|---|---|
+ | Addition / concatenation | price + tax, first + " " + last |
- | Subtraction | total - discount |
* | Multiplication | quantity * price |
/ | Division | total / count |
% | Modulo | value % 2 |
== | Equal | status == "active" |
!= | Not equal | country != "US" |
> | Greater than | amount > 1000 |
>= | Greater than or equal | age >= 18 |
< | Less than | quantity < 10 |
<= | Less than or equal | score <= 100 |
&& | Logical AND | age >= 18 && consent |
|| | Logical OR | isAdmin || isOwner |
! | Logical NOT | !isExpired |
Ternary operator
Use the ternary operator for inline conditionals:
// condition ? valueIfTrue : valueIfFalse
plan == "Pro" ? "Priority Support" : "Standard Support"Referencing variables
Reference variables by their ID in expressions. The variable picker shows available variables when writing an expression.
// Simple reference
clientName
// Arithmetic with variables
unitPrice * quantity
// String operations
"Dear " + clientName + ","Conditional visibility
Use condition expressions to show or hide form fields and document sections dynamically.
Field visibility
Attach a condition to any form field to show/hide it based on other field values:
- Select a form field in the form builder
- Set the Visible when property to a condition expression
- The field only appears when the condition is
true
Example:
- Field: "Company Name"
- Visible when:
accountType == "Business" - Result: The "Company Name" field only shows when the user selects "Business" as account type
Document sections
Conditional sections in the document template show or hide entire blocks of content:
- Wrap content in a conditional container
- Assign an expression to the container
- The content renders only when the expression evaluates to
true
Common patterns
Invoice calculations
// Line item total
quantity * unitPrice
// Subtotal (sum of line items)
item1Total + item2Total + item3Total
// Tax calculation
subtotal * taxRate / 100
// Grand total
subtotal + taxAmount
// Discount
subtotal > 5000 ? subtotal * 0.1 : 0Conditional content
// Show warranty section for hardware products
productCategory == "Hardware"
// Show international shipping fields
shippingCountry != "United States" && shippingCountry != "Canada"
// Show signature block only when terms are accepted
termsAccepted == trueDynamic text
// Pronoun based on selection
gender == "Male" ? "he" : gender == "Female" ? "she" : "they"
// Plural handling
quantity == 1 ? "item" : "items"
// Full address
streetAddress + ", " + city + ", " + state + " " + zipCodeBest practices
- Keep expressions simple — Break complex calculations into multiple computed fields
- Name clearly — Use descriptive names like "Total with Tax" instead of "calc1"
- Test with edge cases — What happens when a referenced variable is empty?
- Use conditions sparingly — Too many conditional fields can confuse respondents
- Document your logic — Use the expression description field to explain complex formulas