DynamicForm.Instance.Decoder (DynamicForm v0.18.1)

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 decoder accepts SurveyJS-compatible JSON format. See: https://surveyjs.io/form-library/documentation

Examples

iex> json = ~s({"id": "my-form", "title": "My Form", "elements": []})
iex> map = Jason.decode!(json)
iex> DynamicForm.Instance.Decoder.decode_instance(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 map into a DynamicForm.Instance struct.

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.

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_instance(data)

Decodes a map into a DynamicForm.Instance struct.

Supports SurveyJS format with pages array or flat elements array.

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.