FormDef class final
A parsed form: its controls, instances, binds, translations and submission settings.
Port of org.javarosa.core.model.FormDef. Phase 2 provides what the
XForm parser builds; Phase 3 adds recalculation (the TriggerableDag),
repeat insertion and deletion, constraints and preloads; navigation is
added in Phase 4.
- Inheritance
-
- Object
- FormElement
- FormDef
- Available extensions
Constructors
- FormDef()
- Creates an empty form.
Properties
- actionController → ActionController
-
Actions registered on this element, by event.
finalinherited
-
additionalAttributes
→ List<
TreeElement> -
Attributes of the control element not handled by the parser, kept
verbatim (e.g.
rows,odk:tag).finalinherited - appearance ↔ String?
-
The
appearanceattribute.getter/setter pairinherited - bind ↔ TreeReference?
-
The absolute reference this element is bound to (
nullfor a trigger withoutref).getter/setter pairinherited -
children
→ List<
FormElement> -
Child elements (empty for questions).
no setteroverride
- dag → TriggerableDag
-
The dependency graph of the calculations and conditions.
no setter
- deepChildCount → int
-
Number of questions at or below this element.
no setteroverride
- defaultSubmission ↔ SubmissionProfile?
-
The default submission profile, if any.
getter/setter pair
-
elementsWithActionTriggeredByToplevelEvent
→ Set<
FormElement> -
Elements whose actions listen to top-level events.
no setter
- evaluationContext → EvaluationContext
-
The evaluation context for the form's expressions: the instances,
jr:itext,jr:choice-nameand custom functions.no setter -
extras
→ Extras<
Object> -
Objects plugins attach to the form, at most one per type (e.g. ODK
Collect's
DynamicPreloadExtraand entitiesEntityFormExtra).final - formXmlPath ↔ String?
-
Where the form XML came from, if known.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasMainInstance → bool
-
Whether the main instance has been set.
no setter
- id ↔ int
-
A form-wide unique id assigned by the parser.
getter/setter pairinherited
- labelInnerText ↔ String?
-
Literal label text (when not localized).
getter/setter pairinherited
- lastSavedSrc ↔ String?
-
The
jr://instance/last-savedsource it was parsed with, if any.getter/setter pair - localizer ↔ Localizer?
-
The translations, if the form has
<itext>.getter/setter pair - mainInstance ↔ FormInstance
-
The main instance.
getter/setter pair
- name ↔ String?
-
The form name (
<meta name>or the title).getter/setter pair -
nonMainInstances
→ Map<
String, DataInstance> -
All secondary instances by name.
no setter
-
outputFragments
→ List<
XPathConditional> -
The
<output>expressions referenced as${n}in labels and hints.final -
parseErrors
→ List<
String> -
Non-fatal errors found while parsing.
final
-
parseWarnings
→ List<
String> -
Warnings found while parsing.
final
- preloader ↔ QuestionPreloader
-
The
jr:preloadhandlers; replace or extend before initialize.getter/setter pair - recordAudioListener ↔ RecordAudioListener?
-
Receives
<odk:recordaudio>requests (replaces JavaRosa's staticRecordAudioActionslistener).getter/setter pair - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sourceXml ↔ String?
-
The XForm XML this form was parsed from (kept for the codec).
getter/setter pair
- textId ↔ String?
-
The itext id of the label. A
;formsuffix is stripped, as in JavaRosa.getter/setter pairinherited - title ↔ String?
-
The form title (
<h:title>).getter/setter pair -
triggerables
→ List<
Triggerable> -
The registered triggerables, in registration order.
no setter
Methods
-
addChild(
FormElement child) → void -
Adds
child. Throws for questions.override -
addEventListener(
void listener(EvaluationEvent event)) → void -
Receives evaluation events (debugging and tracing). Port of
JavaRosa's
EventNotifier. -
addFilterStrategy(
FilterStrategy strategy) → void - Adds a predicate filter strategy tried before the built-in ones.
-
addFunctionHandler(
XPathFunctionHandler handler) → void - Adds a custom XPath function available to the form's expressions.
-
additionalAttribute(
String? namespace, String name) → String? -
The value of additional attribute
nameinnamespace, if present.inherited -
addListener(
FormElementListener listener) → void -
Registers
listener(once).inherited -
addNonMainInstance(
DataInstance instance) → void - Adds a secondary instance under its name.
-
addParseError(
String error) → void - Adds a non-fatal parse error.
-
addParseWarning(
String warning) → void - Adds a parse warning.
-
addSubmissionProfile(
String id, SubmissionProfile profile) → void -
Adds a submission profile with
id. -
addTriggerable(
Triggerable triggerable) → Triggerable - Registers a triggerable, or returns an equal one already registered (whose context then covers both binds).
-
buildIndex(
List< int> indexes, List<int> multiplicities, List<FormElement> elements) → FormIndex? - The index for the given path (multiplicities are kept for repeats only).
-
canCreateRepeat(
TreeReference repeatRef, GroupDef repeat, int currentMultiplicity) → bool -
Whether another instance of
repeatcan be added aftercurrentMultiplicityinstances atrepeatRef: always, unless the repeat is fixed (noAddRemove), and for ajr:countrepeat while the count is larger. -
canCreateRepeatAt(
TreeReference repeatRef, FormIndex repeatIndex) → bool -
Whether a new instance of the repeat at
repeatIndexcan be added. Port ofcanCreateRepeat(TreeReference, FormIndex). -
childAt(
int i) → FormElement? -
The child at
i, ornullif out of range.inherited -
childInstanceRef(
FormIndex index) → TreeReference? -
The instance reference of the element at
index. -
childInstanceRefOf(
List< FormElement> elements, List<int> multiplicities) → TreeReference? -
The instance reference of the last of
elements, with the repeat instances given bymultiplicities(other steps at multiplicity 0);nullif the controls and binds are inconsistent. -
collapseIndex(
FormIndex index, List< int> indexes, List<int> multiplicities, List<FormElement> elements) → void -
Appends the child indices, multiplicities (0 outside repeats) and
elements along
indexto the lists. -
copyItemsetAnswer(
QuestionDef question, TreeElement targetNode, AnswerValue? data) → void -
Deprecated
<copy>itemsets: replaces the copies undertargetNodewith the subtrees of the selected choices (reusing existing copies of still-selected values). Port ofcopyItemsetAnswer. -
createNewRepeat(
FormIndex index) → void -
Adds the repeat instance at
index. Port ofcreateNewRepeat. -
createRepeatInstance(
TreeReference repeatRef) → TreeElement -
Adds a repeat instance at
repeatRef(fully qualified, with the new instance's multiplicity) from the repeat's template, preloads it, firesjr-insertandodk-new-repeat, and evaluates what it affects. -
deleteRepeat(
FormIndex index) → FormIndex -
Deletes the repeat instance containing
index; returns the index of the deleted instance. Port ofdeleteRepeat(FormIndex). -
deleteRepeatInstance(
TreeReference deleteRef) → void -
Removes the repeat instance at
deleteRef, renumbers the following instances and re-evaluates what depended on it. -
descendIntoRepeat(
FormIndex index, int repIndex) → FormIndex -
The index of instance
repIndexof the repeat atindex; -1 means the instance about to be created. -
elementAt(
FormIndex? index) → FormElement -
The element at
index(the form itself outside the form). -
evaluateConstraint(
TreeReference ref, AnswerValue? data) → bool -
Whether
datasatisfies the constraint of the node atref(no answer always does). -
explodeIndex(
FormIndex index) → List< FormElement> -
The elements along
index, top level first. -
fillTemplateString(
String template, TreeReference contextRef, [Map< String, Object?> variables = const {}]) → String -
Replaces
${n}placeholders intemplatewith the values of outputFragments, evaluated atcontextRef. -
finalizeTriggerables(
) → void - Orders the triggerables for evaluation; throws StateError naming the nodes involved when they depend on each other in a cycle.
-
hasAction(
String name) → bool -
Whether the form uses action element
name. -
initialize(
{required bool newInstance}) → void -
Prepares the form for filling: initializes the instances, preloads a
newInstance, picks the default language, fires the load actions and evaluates every calculation and condition. -
isRepeatRelevant(
TreeReference repeatRef) → bool -
Whether the repeat instance at
repeatRefis relevant: its own relevance condition, its parent's relevance and its template's. -
loadXmlInstance(
String instanceXml, {AnswerResolver resolver = defaultAnswerResolver}) → void -
Available on FormDef, provided by the XFormInstanceLoading extension
Replaces the main instance with the saved instanceinstanceXml(typed against the form). Port ofXFormParser.loadXmlInstance. -
localeChanged(
String locale, Localizer localizer) → void -
Called when the current locale of
localizerbecomeslocale.override -
nonMainInstance(
String name) → DataInstance? -
The secondary instance called
name, if any. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
int changes) → void -
Notifies listeners of
changes.inherited -
numRepetitions(
FormIndex index) → int -
The number of instances of the repeat at
index. -
postProcessInstance(
) → void -
Finalization: fires
xforms-revalidateand runs the preloads' finalization steps (such astimestampend). -
preloadInstance(
TreeElement node) → void -
Applies the
jr:preloadvalues tonodeand its descendants (templates excluded). -
processSetValue(
SetValueAction action, TreeReference? context) → TreeReference? -
Performs a
<setvalue>(port ofSetValueAction.processAction). -
publishEvent(
EvaluationEvent event) → void -
Sends
eventto the event listeners. -
registerAction(
String name) → void -
Records that the form uses action element
name. -
registerElementWithActionTriggeredByToplevelEvent(
FormElement e) → void - Records an element inside the body whose actions listen to top-level events.
-
removeEventListener(
void listener(EvaluationEvent event)) → void -
Stops
listenerfrom receiving evaluation events. -
removeListener(
FormElementListener listener) → void -
Unregisters
listener.inherited -
replaceChildAt(
int i, FormElement child) → void -
Replaces child
i. -
saveActionValue(
TreeReference ref, String text) → void -
Stores an action-provided
text(e.g. a location) atref. -
setAdditionalAttribute(
String? namespace, String name, String? value) → void -
Sets, adds or removes (with a
nullvalue) an additional attribute.inherited -
setAnswer(
AnswerValue? value, TreeReference ref) → void -
Sets the answer at
refwithout re-evaluating anything. -
setValue(
AnswerValue? value, TreeReference ref, {bool midSurvey = true}) → void -
Sets
valueatref, re-evaluates what depends on it and, when the value changed, fires the question'sxforms-value-changedactions. -
submissionProfile(
[String? id]) → SubmissionProfile? -
The submission profile with
id, or the default one. -
toString(
) → String -
A string representation of this object.
override
-
triggerTriggerables(
TreeReference ref) → Set< Triggerable> -
Re-evaluates what depends on the node at
ref; returns the triggerables evaluated. -
validate(
{bool markCompleted = true}) → ValidateOutcome? -
Available on FormDef, provided by the FormDefValidation extension
Re-answers every relevant question with its current answer (running required and constraint checks); the first failure, ornullwhen the form is valid. Port ofFormDef.validate/TriggerableDag.validate.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
findQuestionByRef(
TreeReference ref, FormElement element) → QuestionDef? -
The question bound to
refunderelement(repeat-agnostic whenelementis the form). -
getAbsRef(
TreeReference? ref, TreeReference parentRef) → TreeReference -
refanchored toparentRef(which must be absolute); a missingref(a<group>without binding) means the parent itself. -
updateItemsetReferences(
List< FormElement> children) → void -
Computes itemset references for all questions under
children.