Sha256: e092679afb9108b73edc310c9dda3d78c0df796d4010e343fb86ab035d004427
Contents?: true
Size: 1.22 KB
Versions: 13
Compression:
Stored size: 1.22 KB
Contents
# :nodoc: module SimpleForm # :nodoc: module Components # Support for `suffix:` option when using the simple_form gem. When using the # provided `simple_form.rb` initializer everything should be properly setup # to make use of this input component. # # ## Usage # # Render a field with the suffix _CHF_: # # ```erb # <%= f.input :amount, suffix: 'CHF' %> # ``` # # Pass in custom HTML options to the suffix div: # # ```erb # <%= f.input :amount, suffix: 'CHF', suffix_html: { class: 'red-text' } %> # ``` # module Suffix def suffix(_wrapper_options = nil) return unless suffix? @suffix_tag ||= begin additional_classes << 'has-suffix' template.content_tag :div, suffix_label, suffix_html_options end end private def suffix? suffix_label end def suffix_label options[:suffix].presence end def suffix_html_options suffix_html = options.fetch(:suffix_html, {}) suffix_html[:class] = [suffix_html[:class], 'suffix'].compact suffix_html end end end end SimpleForm::Inputs::Base.send(:include, SimpleForm::Components::Suffix)
Version data entries
13 entries across 13 versions & 1 rubygems