Skip to content

Field types ​

Every field is a subtype of the sealed FormFieldDefinition. A switch over a field is exhaustive, and each subtype's copyWith returns its own concrete type.

Shared options ​

Every field type accepts these parameters.

ParameterTypeMeaning
keyStringRequired. Stable value key, unique in the form. Values, rules and formulas ($key) use it.
labelStringRequired, non-blank.
descriptionString?A sentence under the label saying what the field is for.
hintString?Example text inside an empty input.
helpTextString?Longer guidance behind the field's info button.
requiredboolAdds a RequiredValidation at index 0 of validations. The required getter reads it back.
readOnlyboolStarts the field disabled. SetEnabled rules can only narrow further.
validationsIterable<FormValidation>Ordered list of rules. See Validation.

On copyWith, null keeps a text value and a blank string clears description, hint or helpText. copyWith(required: ...) adds or removes only the required rule.

dart
final withHelp = field.copyWith(helpText: 'One line; details go in What happened.');
final optional = field.copyWith(required: false);

Built-in types ​

ClassJSON typeOwn optionsValue
TextFormFieldtextinputKind: TextInputKind (singleLine, multiline, richText, masked); shorthand multiline: trueString
NumberFormFieldnumberdecimal: bool. Bounds come from NumericRangeValidation.int, or FormulaNumber when decimal
MoneyFormFieldmoneydefaultCurrency: String?MoneyValue(amount, currency)
QuantityFormFieldquantitydimension: String?, units: Iterable<String> (the first is the default; empty means the host's unit lookup offers them)QuantityValue(amount, unit)
DurationFormFielddurationnoneDuration
ToggleFormFieldbooleannonebool
ChoiceFormFieldchoicechoices: Iterable<FormChoice> (required), multiple: boolString, or Set<String> when multiple
ReferenceFormFieldreferencetarget: String (a host entity type id, required), multiple: boolrecord id(s)
RatingFormFieldratingmaxStars: int (default 5, at most 10)int from 1 to maxStars; null for no rating
DateTimeFormFielddateTimekind: TemporalKind (date, time, dateTime); shorthand dateOnly: trueDateTime
DateRangeFormFielddateRangenoneDateRangeValue(start, end)
DateTimeRangeFormFielddateTimeRangenoneDateTimeRangeValue(start, end)
AttachmentFormFieldattachmentimagesOnly: bool, multiple: boolList<AttachmentValue>
FormulaFormFieldformulaexpression: String, outputType: FormulaType (both required). Always read-only; has no required or readOnly parameter.computed
CustomFormField<T>your typeIdtypeId, configuration: T, configurationVersion (default 1)yours

Minimum sizes for each type are listed on the Layout page.

Choices ​

dart
ChoiceFormField(
  key: 'severity',
  label: 'Severity',
  required: true,
  choices: const [
    FormChoice(value: 'minor', label: 'Minor'),
    FormChoice(value: 'major', label: 'Major'),
    FormChoice(value: 'critical', label: 'Critical'),
  ],
)

Choice values must be non-blank and unique; labels must be non-blank.

Host services ​

Some types need the host to look things up. FormView takes a callback for each:

FieldFormView parameterSignature
ReferenceFormFieldreferenceSearchFuture<List<FormChoice>> Function(String target, String query, int pageSize)
ReferenceFormFieldreferenceLabelFuture<String?> Function(String target, String value)
MoneyFormField, QuantityFormFieldcodeSearchFuture<List<FormChoice>> Function(String catalog, String? dimension, String query, int pageSize) (catalog is currency or unit)
AttachmentFormFieldattachmentPickerFuture<List<AttachmentValue>?> Function(AttachmentFormField field, List<AttachmentValue> current); null when the user cancels
CustomFormFieldcustomBuilderWidget Function(BuildContext, FormFieldDefinition field, Object? value, ValueChanged<Object?> onChanged)

Formula fields ​

dart
FormulaFormField(
  key: 'line_cost',
  label: 'Line cost',
  expression: r'$qty * $unit_cost',
  outputType: FormulaType.number, // from package:cdx_formula
)

A formula declares no dependency list: its inputs come from compiling the expression against the fields in its scope. See Rules and formulas.

Content nodes ​

Content is not a field and has no value. It sits in the layout tree wherever a field slot can.

ClassJSON typeOptionsRendered by
HeadingContentheadingtext, level (1 to 6, default 2)FormView
TextContenttexttext, formatted: boolFormView
CalloutContentcallouttextFormView
DividerContentdividernoneFormView
SpacerContentspacergridUnits (at least 1)FormView
ImageContentimageassetReference, altText (both non-blank)FormView(assetBuilder:)
DataDisplayContentdataDisplaysourceId, style: DataDisplayStyle (keyValue, table)FormView(dataDisplayBuilder:)
CustomContent<T>customtypeId, configuration: T, configurationVersionNo renderer yet: FormView shows an "Unsupported content" placeholder

Coming later ​

Text formats (email, phone, URL) with implicit validation, input masks, sliders, attachment limits passed to the picker, and per-type presentation variants (choice as radio or chips, toggle as checkbox) are planned. See the Roadmap.