DynamicForm.Parser.FromData (DynamicForm v1.0.0)

Copy Markdown View Source

Decodes SurveyJS-compatible JSON data or maps into DynamicForm.Instance structs.

This module handles the conversion of SurveyJS-format JSON form configurations into proper Elixir structs, including nested elements and special types.

SurveyJS Format

This parser accepts SurveyJS-compatible JSON format. See: https://surveyjs.io/form-library/documentation

Examples

iex> json = ~s({"id": "my-form", "title": "My Form", "elements": []})
iex> DynamicForm.Parser.FromData.parse!(json)
%DynamicForm.Instance{id: "my-form", title: "My Form", elements: []}

iex> map = %{"id" => "my-form", "title" => "My Form", "elements" => []}
iex> DynamicForm.Parser.FromData.parse!(map)
%DynamicForm.Instance{id: "my-form", title: "My Form", elements: []}

Summary

Functions

Decodes question choices.

Decodes a DateTime from an ISO8601 string.

Decodes a single element based on its type.

Decodes a list of elements (questions and panels).

Decodes a panel or HTML element map into an Instance.Element struct.

Decodes a question map into an Instance.Question struct.

Decodes a single validator map into an Instance.Validator struct.

Decodes a validator list.

Parses a JSON string or map into a DynamicForm.Instance struct.

Functions

decode_choices(choices)

Decodes question choices.

SurveyJS supports:

  • Simple strings: ["option1", "option2"]
  • Objects: [{"value": "v1", "text": "Label 1"}, ...]

decode_datetime(string)

Decodes a DateTime from an ISO8601 string.

decode_element(data)

Decodes a single element based on its type.

SurveyJS uses type to distinguish between question types and element types.

decode_elements(elements)

Decodes a list of elements (questions and panels).

decode_panel_or_html(data)

Decodes a panel or HTML element map into an Instance.Element struct.

decode_question(data)

Decodes a question map into an Instance.Question struct.

decode_validator(data)

Decodes a single validator map into an Instance.Validator struct.

decode_validators(validators)

Decodes a validator list.

parse!(instance)

Parses a JSON string or map into a DynamicForm.Instance struct.

Supports SurveyJS format with pages array or flat elements array. An already-parsed %DynamicForm.Instance{} passes through unchanged.