PhoenixKit.Entities.FieldTypes (phoenix_kit v1.5.2)
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.
Returns field types grouped by category.
Returns all categories with their field types.
Returns a list of category names with labels.
Gets the default properties for a field type.
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.
Checks if a field type requires options to be defined.
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", ...}, ...}
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"},
...
]
Gets the default properties for a field type.
Examples
iex> PhoenixKit.Entities.FieldTypes.default_props("text")
%{"placeholder" => "", "max_length" => 255}
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
}
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
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"}