FormBuilderDSL.DSL (form_builder_dsl v0.1.2)

View Source

The core DSL module that provides form building capabilities.

This module provides macros for defining form fields, enums, and form structure. It handles the compilation of form definitions into metadata structures that can be used for rendering, validation, and serialization.

Summary

Types

enum_name()

@type enum_name() :: atom()

enum_values()

@type enum_values() :: [atom()]

field_key()

@type field_key() :: atom()

field_opts()

@type field_opts() :: keyword()

field_type()

@type field_type() :: atom()

Functions

__before_compile__(_)

(macro)

Returns the list of fields defined in the form.

checkbox(key, opts \\ [])

(macro)

color(key, opts \\ [])

(macro)

date(key, opts \\ [])

(macro)

date_time(key, opts \\ [])

(macro)

defenum(name, values)

(macro)

Defines an enum with the given name and values.

Parameters

  • name - The atom name for the enum
  • values - List of atom values for the enum

Example

defenum :status, [:active, :inactive]

This will generate:

  • status_options/0 - Returns list of string values
  • status_labeled_options/0 - Returns list of {label, value} tuples

email(key, opts \\ [])

(macro)

file(key, opts \\ [])

(macro)

form(name, list)

(macro)

Defines a form with the given name and block of field definitions.

Parameters

  • name - The atom name for the form
  • block - A block containing field definitions

Example

form :user do
  text :name
  email(:email)
end

hidden(key, opts \\ [])

(macro)

humanize(atom)

Converts an atom to a human-readable string.

Parameters

  • atom - The atom to convert

Returns

  • A capitalized string with underscores replaced by spaces

Example

iex> FormBuilderDSL.DSL.humanize(:first_name)
"First name"

image(key, opts \\ [])

(macro)

month(key, opts \\ [])

(macro)

multi_select(key, opts \\ [])

(macro)

number(key, opts \\ [])

(macro)

password(key, opts \\ [])

(macro)

radio(key, opts \\ [])

(macro)

range(key, opts \\ [])

(macro)

search(key, opts \\ [])

(macro)

select(key, opts \\ [])

(macro)

switch(key, opts \\ [])

(macro)

tel(key, opts \\ [])

(macro)

text(key, opts \\ [])

(macro)

Defines a text input field.

Parameters

  • key - The atom key for the field
  • opts - Optional field attributes

Options

  • :label - Custom label for the field
  • :required - Whether the field is required
  • :placeholder - Placeholder text
  • :default - Default value
  • :validations - List of validation rules
  • :disabled - Whether the field is disabled

time(key, opts \\ [])

(macro)

url(key, opts \\ [])

(macro)

week(key, opts \\ [])

(macro)