MishkaGervaz.Form.Web.Events.Helpers (MishkaGervaz v0.0.1-alpha.2)

Copy Markdown View Source

Shared helpers for MishkaGervaz.Form.Web.Events and its sub-handlers.

Two reasons these live here rather than inside each sub-handler's __using__ macro:

  1. Reuse across sub-handlers and user overrides. A user module that overrides submit/3 (via use Events.SubmitHandler) can call any helper here without redefining it.
  2. Smaller compiled bytecode per consumer. Pure helpers compile once in this module rather than into every consumer's beam.

Three groups:

  • Typed-param helpers (parse_typed_params/2, sanitize_typed_params/2) — dispatch through field.type_module when set; pass through otherwise.
  • Sanitization helpers (sanitize_string/1, sanitize_list_item/2) — extracted from SanitizationHandler's __using__ macro.
  • Upload helpers (merge_uploaded_files/4) — extracted from SubmitHandler's __using__ macro.

See MishkaGervaz.Form.Web.Events, MishkaGervaz.Form.Web.Events.SanitizationHandler, MishkaGervaz.Form.Web.Events.SubmitHandler, MishkaGervaz.Form.Web.Events.ValidationHandler, and the sibling sub-handlers.

Summary

Functions

Runs each field's FieldType.validate/2 over params and returns a list of {field_atom, message} pairs ready to merge into an AshPhoenix.Form's errors keyword list. Fields whose type module doesn't implement validate/2 (detected via the cached :custom_validate? flag) are skipped.

Functions

validate_typed_params(fields, params)

@spec validate_typed_params([map()], map()) :: [{atom(), String.t()}]

Runs each field's FieldType.validate/2 over params and returns a list of {field_atom, message} pairs ready to merge into an AshPhoenix.Form's errors keyword list. Fields whose type module doesn't implement validate/2 (detected via the cached :custom_validate? flag) are skipped.