Skip to content

Instantly share code, notes, and snippets.

@wkrsz
Created September 15, 2013 12:01
Show Gist options
  • Save wkrsz/6570175 to your computer and use it in GitHub Desktop.
Save wkrsz/6570175 to your computer and use it in GitHub Desktop.
I'm using SimpleForm and I wanted to display validation errors as label tags, which has (arguably) accessibility benefits. Here's how to add a custom error_label component that adds correct "for" attribute.
module SimpleForm
module Components
module ErrorLabel
def error_label
if has_errors?
@builder.label(label_target, error_text, label_html_options)
end
end
end
end
Inputs::Base.send(:include, SimpleForm::Components::ErrorLabel)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment