diff options
Diffstat (limited to 'src/components/shared/field_errors.cr')
-rw-r--r-- | src/components/shared/field_errors.cr | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/components/shared/field_errors.cr b/src/components/shared/field_errors.cr new file mode 100644 index 0000000..3f2937a --- /dev/null +++ b/src/components/shared/field_errors.cr @@ -0,0 +1,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 |