added f.input_only to cater for when you only want an INPUT tag and nothing else
This commit is contained in:
parent
657a76c4e5
commit
3d100e8b99
|
@ -90,6 +90,22 @@ module SimpleForm
|
|||
end
|
||||
end
|
||||
alias :attribute :input
|
||||
|
||||
# Helper for outputting only the input tag, no wrapper, errors, label etc
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
# simple_form_for @user do |f|
|
||||
# f.input_only :name
|
||||
# end
|
||||
#
|
||||
def input_only(attribute_name, options={})
|
||||
options.merge!({:components => [:input], :wrapper => false})
|
||||
column = find_attribute_column(attribute_name)
|
||||
input_type = default_input_type(attribute_name, column, options)
|
||||
klass = self.class.mappings[input_type] || self.class.const_get("#{input_type.to_s.camelize}Input")
|
||||
klass.new(self, attribute_name, column, input_type, options).render
|
||||
end
|
||||
|
||||
# Helper for dealing with association selects/radios, generating the
|
||||
# collection automatically. It's just a wrapper to input, so all options
|
||||
|
|
|
@ -377,6 +377,17 @@ class FormBuilderTest < ActionView::TestCase
|
|||
assert_select 'form div.input.required.string.field_with_errors'
|
||||
end
|
||||
|
||||
# ONLY THE INPUT TAG
|
||||
test "builder input_only should only render the input tag, nothing else" do
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.input_only :name
|
||||
end
|
||||
assert_select 'form > input.required.string'
|
||||
assert_select 'div.string', false
|
||||
assert_select 'label', false
|
||||
assert_select '.hint', false
|
||||
end
|
||||
|
||||
# WITHOUT OBJECT
|
||||
test 'builder should generate properly when object is not present' do
|
||||
with_form_for :project, :name
|
||||
|
|
Loading…
Reference in New Issue