Add MoneyInput

Fix https://github.com/plataformatec/simple_form/issues/1579
This commit is contained in:
Felipe Renan 2019-01-21 14:46:31 -02:00
parent 7cbedde3de
commit 1bbdd7c5be
4 changed files with 26 additions and 0 deletions

View File

@ -32,6 +32,7 @@ module SimpleForm
map_type :country, :time_zone, to: SimpleForm::Inputs::PriorityInput
map_type :boolean, to: SimpleForm::Inputs::BooleanInput
map_type :hidden, to: SimpleForm::Inputs::HiddenInput
map_type :money, to: SimpleForm::Inputs::MoneyInput
def self.discovery_cache
@discovery_cache ||= {}

View File

@ -21,5 +21,6 @@ module SimpleForm
autoload :RangeInput
autoload :StringInput
autoload :TextInput
autoload :MoneyInput
end
end

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
module SimpleForm
module Inputs
class MoneyInput < Base
enable :placeholder, :maxlength, :minlength
def input(wrapper_options = nil)
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
@builder.text_field(attribute_name, merged_input_options)
end
end
end
end

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
require 'test_helper'
class MoneyTest < ActionView::TestCase
test 'input maps money field to string attribute' do
with_input_for @user, :amount, :money
assert_select "input.money[type=text][name='user[amount]']"
end
end