Permalink
Browse files

fill_out -> values=, and fix subforms

  • Loading branch information...
clayallsopp committed Nov 5, 2012
1 parent 71c86fe commit 713ffc461a693ccb93ff7f38336ad730958e860c
Showing with 9 additions and 9 deletions.
  1. +5 −3 lib/formotion/form/form.rb
  2. +4 −6 spec/form_spec.rb
@@ -194,7 +194,7 @@ def sub_render
kv
end
- def fill_out(data)
+ def values=(data)
self.sections.each {|section|
if section.select_one?
# see if one of the select one value is used
@@ -210,15 +210,17 @@ def fill_out(data)
# If this row is part of a template
# use the parent's key
row.value = data[row.template_parent_key] if data.has_key?(row.template_parent_key)
- #elsif row.subform
- # self.class.new(row.subform).fill_out(data)
+ elsif row.subform
+ row.subform.to_form.values = data
else
row.value = data[row.key] if data.has_key?(row.key)
end
}
end
}
end
+
+ alias_method :fill_out, :values=
#########################
# Persisting Forms
View
@@ -77,7 +77,7 @@
title: 'Email'
}]}])
- @form.fill_out :email => 'something@email.com'
+ @form.values = { :email => 'something@email.com' }
row = @form.sections[0].rows[0]
row.value.should == 'something@email.com'
@@ -102,7 +102,7 @@
}]
}])
- @form.fill_out :b => true
+ @form.values = { :b => true }
row = @form.sections[0].rows[0]
row.value.should == nil
@@ -131,7 +131,7 @@
}])
- @form.fill_out :nicknames => ["Nici", "Sam"]
+ @form.values = { :nicknames => ["Nici", "Sam"] }
row = @form.sections[0].rows[0]
row.value.should == ["Nici", "Sam"]
@@ -161,7 +161,6 @@
@form.render[:subform][:email].should == 'something@email.com'
end
-=begin
it "fills out subform values correctly" do
@form = Formotion::Form.new(sections: [{
rows: [{
@@ -179,13 +178,12 @@
}
}]}])
- @form.fill_out :email => 'something@email.com'
+ @form.values = { :email => 'something@email.com' }
subform = @form.sections[0].rows[0].subform.to_form
row = subform.sections[0].rows[0]
row.value.should == 'something@email.com'
end
-=end
it "hashifying should be same as input" do
h = {

0 comments on commit 713ffc4

Please sign in to comment.