Current section
Files
Jump to
Current section
Files
lib/backpex/fields/textarea.ex
defmodule Backpex.Fields.Textarea do
@config_schema [
placeholder: [
doc: "Placeholder value or function that receives the assigns.",
type: {:or, [:string, {:fun, 1}]}
],
debounce: [
doc: "Timeout value (in milliseconds), \"blur\" or function that receives the assigns.",
type: {:or, [:pos_integer, :string, {:fun, 1}]}
],
throttle: [
doc: "Timeout value (in milliseconds) or function that receives the assigns.",
type: {:or, [:pos_integer, {:fun, 1}]}
],
rows: [
doc: "Number of visible text lines for the control.",
type: :non_neg_integer,
default: 2
],
readonly: [
doc: "Sets the field to readonly. Also see the [panels](/guides/fields/readonly.md) guide.",
type: {:or, [:boolean, {:fun, 1}]}
]
]
@moduledoc """
A field for handling long text values.
## Field-specific options
See `Backpex.Field` for general field options.
#{NimbleOptions.docs(@config_schema)}
"""
use Backpex.Field, config_schema: @config_schema
@impl Backpex.Field
def render_value(assigns) do
~H"""
<p
class={[
@live_action in [:index, :resource_action] && "truncate",
@live_action == :show && "overflow-x-auto whitespace-pre-wrap"
]}
phx-no-format
><%= HTML.pretty_value(@value) %></p>
"""
end
@impl Backpex.Field
def render_form(assigns) do
~H"""
<div>
<Layout.field_container>
<:label align={Backpex.Field.align_label(@field_options, assigns, :top)}>
<Layout.input_label for={@form[@name]} text={@field_options[:label]} />
</:label>
<BackpexForm.input
type="textarea"
field={@form[@name]}
placeholder={@field_options[:placeholder]}
rows={@field_options[:rows]}
translate_error_fun={Backpex.Field.translate_error_fun(@field_options, assigns)}
help_text={Backpex.Field.help_text(@field_options, assigns)}
phx-debounce={Backpex.Field.debounce(@field_options, assigns)}
phx-throttle={Backpex.Field.throttle(@field_options, assigns)}
readonly={@readonly}
disabled={@readonly}
/>
</Layout.field_container>
</div>
"""
end
end