diff --git a/lib/ProMotion/thirdparty/formotion_screen.rb b/lib/ProMotion/thirdparty/formotion_screen.rb index 0853d29..ee68719 100644 --- a/lib/ProMotion/thirdparty/formotion_screen.rb +++ b/lib/ProMotion/thirdparty/formotion_screen.rb @@ -2,7 +2,7 @@ module ProMotion if defined?(Formotion) && defined?(Formotion::FormController) class FormotionScreen < Formotion::FormController include ProMotion::ScreenModule - + def self.new(args = {}) s = self.alloc.initWithStyle(UITableViewStyleGrouped) s.on_create(args) if s.respond_to?(:on_create) @@ -19,6 +19,8 @@ module ProMotion s.tableView.allowsSelectionDuringEditing = true s.title = t + s.form.on_submit { |form| s.on_submit(form) if s.respond_to?(:on_submit) } + s end @@ -28,11 +30,11 @@ module ProMotion self.form.controller = self self.tableView.reloadData end - + def screen_setup self.title = self.class.send(:get_title) end - + def loadView super self.send(:on_load) if self.respond_to?(:on_load) diff --git a/spec/helpers/table_screen_formotion.rb b/spec/helpers/table_screen_formotion.rb index bb5a469..dd72147 100644 --- a/spec/helpers/table_screen_formotion.rb +++ b/spec/helpers/table_screen_formotion.rb @@ -1,4 +1,5 @@ class TestFormotionScreen < PM::FormotionScreen + attr_accessor :submitted_form title "Formotion Test" @@ -22,4 +23,8 @@ class TestFormotionScreen < PM::FormotionScreen } end + def on_submit(form) + self.submitted_form = form + end + end diff --git a/spec/unit/tables/formotion_screen_spec.rb b/spec/unit/tables/formotion_screen_spec.rb index f953e81..502b928 100644 --- a/spec/unit/tables/formotion_screen_spec.rb +++ b/spec/unit/tables/formotion_screen_spec.rb @@ -13,4 +13,10 @@ describe "PM::FormotionScreen" do @screen.title.should == "Formotion Test" end + it "should fire the on_submit method when form is submitted" do + @screen.form.submit + @screen.submitted_form.should.not.be.nil + @screen.submitted_form.render.should.be.kind_of(Hash) + end + end