Created
September 15, 2013 12:01
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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