Last active
November 5, 2015 19:23
-
-
Save alkalinecoffee/2c0dd28ca064897aea24 to your computer and use it in GitHub Desktop.
custom simple form component
This file contains hidden or 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
SimpleForm.setup do |config| | |
config.wrappers :half_width_checkboxes, tag: 'div', class: 'row', error_class: 'has-error' do |b| | |
b.use :html5 | |
b.wrapper tag: 'div', class: 'col-md-5' do |ba| | |
ba.wrapper tag: 'div', class: 'panel panel-default' do |bb| | |
bb.wrapper tag: 'div', class: 'panel-heading' do |bc| | |
bc.use :h_label, class: 'panel-title' | |
end | |
bb.wrapper tag: 'div', class: 'panel-body' do |bc| | |
bc.use :error, wrap_with: { tag: 'span', class: 'help-block' } | |
bc.use :hint, wrap_with: { tag: 'p', class: 'help-block' } | |
bc.use :input | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or 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
# this example shows how to essentially replace the | |
# default label tag with your own custom tag by using | |
# a simple_form custom component | |
module SimpleForm | |
module Components | |
# Needs to be enabled in order to do automatic lookups | |
module CustomLabels | |
# Name of the component method | |
def h_label(wrapper_options = nil) | |
content_tag(:h4, self.label_text, wrapper_options) | |
end | |
end | |
end | |
end | |
SimpleForm::Inputs::Base.send(:include, SimpleForm::Components::CustomLabels) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment