Created
July 7, 2014 15:56
-
-
Save dirkkelly/aec75016bb10a945d798 to your computer and use it in GitHub Desktop.
Simple Form Bootstrap 3 input group WIP
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 After | |
def after | |
@after ||= begin | |
options[:after].to_s.html_safe if options[:after].present? | |
end | |
end | |
def has_after? | |
after.present? | |
end | |
end | |
end | |
end | |
SimpleForm::Inputs::Base.send(:include, SimpleForm::Components::After) |
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 Before | |
def before | |
@before ||= begin | |
options[:before].to_s.html_safe if options[:before].present? | |
end | |
end | |
def has_before? | |
before.present? | |
end | |
end | |
end | |
end | |
SimpleForm::Inputs::Base.send(:include, SimpleForm::Components::Before) |
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
SimpleForm.setup do |config| | |
# your code here | |
config.wrappers :bootstrap3, tag: "div", error_class: "has-error" do |b| | |
b.use :html5 | |
b.use :min_max | |
b.use :maxlength | |
b.use :placeholder | |
b.optional :pattern | |
b.optional :readonly | |
b.use :input | |
b.use :hint, wrap_with: { tag: "span", class: "help-block" } | |
b.use :error, wrap_with: { tag: "span", class: "help-block has-error" } | |
end | |
config.wrappers :input_group, tag: "div", error_class: "has-error" do |b| | |
b.use :html5 | |
b.wrapper tag: :div, class: "input-group" do |ba| | |
ba.optional :before, wrap_with: { tag: :div, class: "input-group-addon" } | |
ba.use :input | |
ba.optional :after, wrap_with: { tag: :div, class: "input-group-addon" } | |
end | |
b.use :hint, wrap_with: { tag: "span", class: "help-block" } | |
b.use :error, wrap_with: { tag: "span", class: "help-block has-error" } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment