mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-05-24 09:13:24 +08:00
Added on_submit method and test.
This commit is contained in:
8
lib/ProMotion/thirdparty/formotion_screen.rb
vendored
8
lib/ProMotion/thirdparty/formotion_screen.rb
vendored
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user