Created
June 18, 2022 19:35
-
-
Save anka/650fa97fd5cbaf2f0ab761dcf67ef326 to your computer and use it in GitHub Desktop.
Custom currency input using SimpleForm
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
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