Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add basic file input with specs. This is a very simple addition that …

…allow the use of :as => :file to get a file input
  • Loading branch information...
commit 26b1248f0c5f887dd1577c97a52d143dff5138bd 1 parent d78390d
@negonicrac negonicrac authored
View
3  README.textile
@@ -67,6 +67,7 @@ h2. The Available Inputs
* :boolean_select (a yes/no select box)
* :string (a text field) - default for :string column types
* :numeric (a text field, like string) - default for :integer, :float and :decimal column types
+* :file (a file field)
The documentation is pretty good for each of these (what it does, what the output is, etc) so go check it out.
@@ -74,7 +75,7 @@ The documentation is pretty good for each of these (what it does, what the outpu
h3. One day...
* calendars and other more humanized date/time selections
-* vanilla html file selection to work well with things like ThoughtBot's "Paperclip":http://www.thoughtbot.com/projects/paperclip
+* -vanilla html file selection to work well with things like ThoughtBot's "Paperclip":http://www.thoughtbot.com/projects/paperclip-
* flash-based multi-file selection
* an interface for tagging and other has_many_through style associations
View
6 lib/justin_french/formtastic.rb
@@ -350,6 +350,12 @@ def numeric_input(method, options)
input_label(method, options) +
template.text_field(@object_name, method, default_string_options(method))
end
+
+ # Outputs label and file field
+ def file_input(method, options)
+ input_label(method, options) +
+ template.file_field(@object_name, method)
+ end
# Outputs a fieldset with a legend for the method label, and a ordered list (ol) of list
View
34 spec/formtastic_spec.rb
@@ -367,7 +367,7 @@ class Author; end
end
it 'should call the corresponding input method' do
- [:select, :radio, :password, :text, :date, :datetime, :time, :boolean, :boolean_select, :string, :numeric].each do |input_style|
+ [:select, :radio, :password, :text, :date, :datetime, :time, :boolean, :boolean_select, :string, :numeric, :file].each do |input_style|
@new_post.stub!(:generic_column_name)
@new_post.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
semantic_form_for(@new_post) do |builder|
@@ -1188,6 +1188,38 @@ class Author; end
end
+ describe ':as => :file' do
+ setup do
+ @new_post.stub!(:some_file)
+ @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 50))
+
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:some_file, :as => :file))
+ end
+ end
+
+ it 'should have a file class on the wrapper' do
+ output_buffer.should have_tag('form li.file')
+ end
+
+ it 'should have a post_some_file_input id on the wrapper' do
+ output_buffer.should have_tag('form li#post_some_file_input')
+ end
+
+ it 'should generate a label for the input' do
+ output_buffer.should have_tag('form li label')
+ output_buffer.should have_tag('form li label[@for="post_some_file"')
+ output_buffer.should have_tag('form li label', /Some file/)
+ end
+
+ it 'should generate a file input' do
+ output_buffer.should have_tag('form li input')
+ output_buffer.should have_tag('form li input#post_some_file')
+ output_buffer.should have_tag('form li input[@type="file"]')
+ output_buffer.should have_tag('form li input[@name="post[some_file]"]')
+ end
+ end
+
end
describe '#input_field_set' do
Please sign in to comment.
Something went wrong with that request. Please try again.