Skip to content

Instantly share code, notes, and snippets.

@anka
Created June 18, 2022 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anka/650fa97fd5cbaf2f0ab761dcf67ef326 to your computer and use it in GitHub Desktop.
Save anka/650fa97fd5cbaf2f0ab761dcf67ef326 to your computer and use it in GitHub Desktop.
Custom currency input using SimpleForm
class CurrencyInput < SimpleForm::Inputs::StringInput
def input(wrapper_options)
input_options = input_html_options.merge({data: {autonumeric: true}})
merged_input_options = merge_wrapper_options(input_options, wrapper_options)
template.content_tag(:div, class: 'input-group') do
template.concat span_currency_sign
template.concat @builder.text_field(attribute_name, merged_input_options)
end
end
def span_currency_sign
template.content_tag(:span, class: 'input-group-addon') do
template.concat '€'.html_safe
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment