Sha256: 33ea145093f591f77dca0675c3c978b0badfce101002f3bf5f9d5136485415cc

Contents?: true

Size: 1.12 KB

Versions: 17

Compression:

Stored size: 1.12 KB

Contents

module Eac
  module CommonFormHelper
    class FormBuilder
      module CurrencyField
        def currency_field(field_name, options = {})
          hidden_id = SecureRandom.hex(5)
          visible_id = SecureRandom.hex(5)
          cf = field(field_name, options) do
            form.hidden_field(field_name, id: hidden_id) <<
            helper.text_field_tag("#{field_name}_visible", '',
                                  id: visible_id, class: 'form-control')
          end
          cf << javascript_currency_mask(hidden_id, visible_id)
        end

        private

        def javascript_currency_mask(hidden_id, visible_id)
          helper.content_tag :script do
            helper.raw("new CurrencyField('#{hidden_id}', '#{visible_id}', " \
                "#{mask_money_options});")
          end
        end

        def mask_money_options
          <<-eos
{
  prefix: '#{I18n.t('number.currency.format.unit')} ',
  allowNegative: true,
  thousands: '#{I18n.t('number.currency.format.delimiter')}',
  decimal: '#{I18n.t('number.currency.format.separator')}',
  affixesStay: false
}
          eos
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
eac_rails_utils-0.8.0 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.7.1 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.7.0 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.6.0 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.5.0 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.4.0 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.3.0 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.2.2 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.2.1 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.2.0 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.1.15 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.1.14 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.1.13 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.1.12 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.1.11 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.1.10 lib/eac/common_form_helper/form_builder/currency_field.rb
eac_rails_utils-0.0.1 lib/eac/common_form_helper/form_builder/currency_field.rb