FormBuilderDSL
A clean, minimal, and extensible DSL for defining structured, dynamic forms in Elixir.
FormBuilderDSL helps teams write intuitive, maintainable forms with metadata structures that can power:
- Web-based LiveView and HTML rendering
- JSON-serializable form schemas for APIs
- Dynamic admin and internal tool UIs
โจ Features
- Declarative definitions for form fields
- Reusable
defenum/2macro for dropdown/select support - Generates metadata as
FormBuilderDSL.Fieldstructs - Support for text and select inputs (more coming!)
- Runtime-safe enum management using
ETS - Clean rendering logic that plays well with Phoenix Components
๐งช Example
defmodule MyForm do
use FormBuilderDSL
defenum :status, [:active, :inactive, :archived]
form :user do
text :name
select :status, options: status_labeled_options()
end
end
๐ฆ Installation
Add the dependency to your mix.exs:
def deps do
[
{:form_builder_dsl, "~> 0.1.0"}
]
end
Then run:
mix deps.get
๐ Optional: Add Formatter Settings
To keep the DSL syntax clean and bracket-free, add the following to your .formatter.exs:
[
import_deps: [:form_builder_dsl],
locals_without_parens: [
form: 2,
defenum: 2,
text: 1,
text: 2,
select: 1,
select: 2,
date_time: 1,
date_time: 2
]
]
This tells the formatter not to wrap parentheses around common DSL macros.
๐ License
MIT ยฉ Pranav J