Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dirkkelly/aec75016bb10a945d798 to your computer and use it in GitHub Desktop.
Save dirkkelly/aec75016bb10a945d798 to your computer and use it in GitHub Desktop.
Simple Form Bootstrap 3 input group WIP
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)
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)
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