aboutsummaryrefslogtreecommitdiff
path: root/src/components/shared/field_errors.cr
blob: 3f2937a0785708072879af57740a1d2e5bb693ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Shared::FieldErrors(T) < BaseComponent
  needs attribute : Avram::PermittedAttribute(T)

  # Customize the markup and styles to match your application
  def render
    unless attribute.valid?
      div class: "error" do
        text "#{label_text} #{attribute.errors.first}"
      end
    end
  end

  def label_text : String
    Wordsmith::Inflector.humanize(attribute.name.to_s)
  end
end