DynamicForm.CarryForward (DynamicForm v1.0.0)

Copy Markdown View Source

SurveyJS "carry forward": a question whose choices come from another question — one choice per entry of a nested form, or another choice question's own choices, optionally narrowed by choicesFromQuestionMode.

One function for each side of the lifecycle:

  • resolve_choices/2 — at render time, a question's effective choices (its own when no carry-forward is declared).
  • prune_values/4 — at cast time, drop stored values the source no longer offers.

Internal module — not part of the public API.

Summary

Functions

Drops values of a carried-forward question that its source no longer offers — the entry they referenced was deleted, or the option was taken out of the definition. Runs before validate_required so emptying a required field errors as it would have.

A question's choices as {text, value} tuples: its own choices, or — when it declares choicesFromQuestion — one choice per entry of the source question.

Functions

prune_values(changeset, questions, params, opts)

Drops values of a carried-forward question that its source no longer offers — the entry they referenced was deleted, or the option was taken out of the definition. Runs before validate_required so emptying a required field errors as it would have.

A source that resolves to nothing still prunes: keeping ids for entries the same submission deletes would hand the application a payload that contradicts itself. Only a source we cannot observe is left alone — see carried_source_values/3.

params carries entry-local values merged over form-level ones, so a source name resolves the same way it does when rendering.

resolve_choices(question, opts)

A question's choices as {text, value} tuples: its own choices, or — when it declares choicesFromQuestion — one choice per entry of the source question.

The source name resolves innermost-first, matching how {field} expressions scope inside a template: the enclosing entry's values first, then form-level. That is what lets a field inside one entry list "this entry's own children" as well as a top-level nested form's entries.

Reads from opts: :questions and :entry_questions (name → question maps for the form and enclosing entry scopes), :form_data and :entry_data (their current values).