PhoenixKit.Entities.FieldTypes (phoenix_kit v1.6.15)
View SourceField type definitions and utilities for the Entities system.
This module defines all supported field types for entity definitions, including their properties, validation rules, and rendering information.
Supported Field Types
Basic Text Types
- text: Single-line text input
- textarea: Multi-line text area
- email: Email address with validation
- url: URL with validation
- rich_text: Rich HTML editor (TinyMCE/CKEditor-like)
Numeric Types
- number: Numeric input (integer or decimal)
Boolean Types
- boolean: True/false toggle or checkbox
Date/Time Types
- date: Date picker (YYYY-MM-DD format)
Choice Types
- select: Dropdown selection (single choice)
- radio: Radio button group (single choice)
- checkbox: Checkbox group (multiple choices)
Usage Examples
# Get all field types
field_types = PhoenixKit.Entities.FieldTypes.all()
# Get field type info
text_info = PhoenixKit.Entities.FieldTypes.get_type("text")
# Get field types by category
basic_types = PhoenixKit.Entities.FieldTypes.by_category(:basic)
# Check if field type requires options
PhoenixKit.Entities.FieldTypes.requires_options?("select") # => true
Summary
Functions
Returns all field types as a map.
Helper to create a boolean field.
Returns field types grouped by category.
Returns all categories with their field types.
Returns a list of category names with labels.
Helper to create a checkbox field with options.
Gets the default properties for a field type.
Helper to create an email field.
Returns field types suitable for a field picker UI.
Gets information about a specific field type.
Returns a list of all field type names.
Creates a new field definition with default values.
Helper to create a number field.
Helper to create a radio button field with options.
Checks if a field type requires options to be defined.
Helper to create a rich text field.
Helper to create a select field with options.
Helper to create a text field.
Helper to create a textarea field.
Checks if a field type exists.
Validates a field definition map.
Types
@type field_category() :: :basic | :numeric | :boolean | :datetime | :choice
@type field_type() :: String.t()
Functions
Returns all field types as a map.
Examples
iex> PhoenixKit.Entities.FieldTypes.all()
%{"text" => %{name: "text", ...}, ...}
Helper to create a boolean field.
Examples
iex> PhoenixKit.Entities.FieldTypes.boolean_field("active", "Is Active", default: true)
%{"type" => "boolean", "key" => "active", "label" => "Is Active", "default" => true, ...}
Returns field types grouped by category.
Examples
iex> PhoenixKit.Entities.FieldTypes.by_category(:basic)
[%{name: "text", ...}, %{name: "textarea", ...}, ...]
Returns all categories with their field types.
Examples
iex> PhoenixKit.Entities.FieldTypes.categories()
%{
basic: [%{name: "text", ...}, ...],
numeric: [%{name: "number", ...}],
...
}
Returns a list of category names with labels.
Examples
iex> PhoenixKit.Entities.FieldTypes.category_list()
[
{:basic, "Basic"},
{:numeric, "Numeric"},
...
]
Helper to create a checkbox field with options.
Examples
iex> PhoenixKit.Entities.FieldTypes.checkbox_field("tags", "Tags", ["Featured", "Popular", "New"])
%{"type" => "checkbox", "key" => "tags", "label" => "Tags", "options" => ["Featured", "Popular", "New"], ...}
Gets the default properties for a field type.
Examples
iex> PhoenixKit.Entities.FieldTypes.default_props("text")
%{"placeholder" => "", "max_length" => 255}
Helper to create an email field.
Examples
iex> PhoenixKit.Entities.FieldTypes.email_field("email", "Email Address", required: true)
%{"type" => "email", "key" => "email", "label" => "Email Address", "required" => true, ...}
Returns field types suitable for a field picker UI.
Formats the data for use in select dropdowns or type choosers.
Examples
iex> PhoenixKit.Entities.FieldTypes.for_picker()
[
%{value: "text", label: "Text", category: "Basic", icon: "hero-pencil"},
...
]
Gets information about a specific field type.
Returns nil if the type doesn't exist.
Examples
iex> PhoenixKit.Entities.FieldTypes.get_type("text")
%{name: "text", label: "Text", ...}
iex> PhoenixKit.Entities.FieldTypes.get_type("invalid")
nil
Returns a list of all field type names.
Examples
iex> PhoenixKit.Entities.FieldTypes.list_types()
["text", "textarea", "number", ...]
Creates a new field definition with default values.
Examples
iex> PhoenixKit.Entities.FieldTypes.new_field("text", "my_field", "My Field")
%{
"type" => "text",
"key" => "my_field",
"label" => "My Field",
"required" => false,
"default" => "",
"validation" => %{},
"placeholder" => "",
"max_length" => 255
}
# With options for choice fields
iex> PhoenixKit.Entities.FieldTypes.new_field("select", "category", "Category", options: ["Tech", "Business"])
%{
"type" => "select",
"key" => "category",
"label" => "Category",
"required" => false,
"options" => ["Tech", "Business"],
...
}
# With required flag
iex> PhoenixKit.Entities.FieldTypes.new_field("text", "name", "Name", required: true)
%{"type" => "text", "key" => "name", "label" => "Name", "required" => true, ...}
Helper to create a number field.
Examples
iex> PhoenixKit.Entities.FieldTypes.number_field("age", "Age")
%{"type" => "number", "key" => "age", "label" => "Age", ...}
Helper to create a radio button field with options.
Examples
iex> PhoenixKit.Entities.FieldTypes.radio_field("priority", "Priority", ["Low", "Medium", "High"])
%{"type" => "radio", "key" => "priority", "label" => "Priority", "options" => ["Low", "Medium", "High"], ...}
Checks if a field type requires options to be defined.
Examples
iex> PhoenixKit.Entities.FieldTypes.requires_options?("select")
true
iex> PhoenixKit.Entities.FieldTypes.requires_options?("text")
false
Helper to create a rich text field.
Examples
iex> PhoenixKit.Entities.FieldTypes.rich_text_field("content", "Content", required: true)
%{"type" => "rich_text", "key" => "content", "label" => "Content", "required" => true, ...}
Helper to create a select field with options.
Examples
iex> PhoenixKit.Entities.FieldTypes.select_field("category", "Category", ["Tech", "Business", "Other"])
%{"type" => "select", "key" => "category", "label" => "Category", "options" => ["Tech", "Business", "Other"], ...}
iex> PhoenixKit.Entities.FieldTypes.select_field("status", "Status", ["Active", "Inactive"], required: true)
%{"type" => "select", "key" => "status", "label" => "Status", "options" => ["Active", "Inactive"], "required" => true, ...}
Helper to create a text field.
Examples
iex> PhoenixKit.Entities.FieldTypes.text_field("name", "Full Name", required: true)
%{"type" => "text", "key" => "name", "label" => "Full Name", "required" => true, ...}
Helper to create a textarea field.
Examples
iex> PhoenixKit.Entities.FieldTypes.textarea_field("bio", "Biography")
%{"type" => "textarea", "key" => "bio", "label" => "Biography", ...}
Checks if a field type exists.
Examples
iex> PhoenixKit.Entities.FieldTypes.valid_type?("text")
true
iex> PhoenixKit.Entities.FieldTypes.valid_type?("invalid")
false
Validates a field definition map.
Checks that the field has all required properties and valid values.
Examples
iex> field = %{"type" => "text", "key" => "title", "label" => "Title"}
iex> PhoenixKit.Entities.FieldTypes.validate_field(field)
{:ok, field}
iex> invalid_field = %{"type" => "invalid", "key" => "test"}
iex> PhoenixKit.Entities.FieldTypes.validate_field(invalid_field)
{:error, "Invalid field type: invalid"}