Add MoneyInput
Fix https://github.com/plataformatec/simple_form/issues/1579
This commit is contained in:
parent
7cbedde3de
commit
1bbdd7c5be
|
@ -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 ||= {}
|
||||
|
|
|
@ -21,5 +21,6 @@ module SimpleForm
|
|||
autoload :RangeInput
|
||||
autoload :StringInput
|
||||
autoload :TextInput
|
||||
autoload :MoneyInput
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue