motion-form 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93259a7e0e32f3c910f42236b224ac39f740e3a5
4
- data.tar.gz: a406a91fe8a71febc9e362cbce1676ad57b9dd78
3
+ metadata.gz: 8f2148d8f02ba7ad77a2b2f268a3eae119193625
4
+ data.tar.gz: 3051d088e431e7b8dc89a1af6cba627cfa7b29a3
5
5
  SHA512:
6
- metadata.gz: 042d1cabbe16fcca39b1ae14fdba95aca48137bce45d32439385894e1689d857b1e1c50ac6f7ebe8e3debc2fe52163e791970e4bbdd36d0aaa8678018a068f8e
7
- data.tar.gz: a87072db409e61c051e153871ed90f9536d6f1f9800d97b9348e0b515feb9e781d327f83de90c12a1f27bfc001dfa4dfd2a44bf5cfe351e369f0d9ba04e7aa02
6
+ metadata.gz: 456675c8d4b05bc009f91031a82a9979cd2d0ff85fb9e950d5f155d1db4818b3bed1d8cb474215ba71cbf18d81e9d34084b4c18edbb1198e9c3d65a71998de4b
7
+ data.tar.gz: 4436a75ae574dc5939f319cfed6441fc21b6946d06e3f6a57e71d96187886c5cf27e737ccd13980dfec9b838adbf05be6f7de00a14516f5db05f89e634703ad1
data/README.md CHANGED
@@ -28,6 +28,8 @@ form = MotionForm.form_for(view) do |form|
28
28
  section.input :twitter, icon: :twitter
29
29
  section.input :website, icon: :website
30
30
  section.input :bio, icon: :info
31
+
32
+ section.button :submit, action: submit
31
33
  end
32
34
 
33
35
  form.section 'Account' do |section|
@@ -36,19 +38,52 @@ form = MotionForm.form_for(view) do |form|
36
38
  end
37
39
  end
38
40
 
41
+ def submit
42
+ -> do
43
+ form.render # { name: 'Devon',
44
+ # username: 'dblandin',
45
+ # pinterest: '',
46
+ # twitter: 'dblandin',
47
+ # website: 'http://github.com/dblandin',
48
+ # bio: 'Rubyist in Chicago' }
49
+ end
50
+ end
51
+
39
52
  def push_email_controller
40
- lambda do
53
+ -> do
41
54
  # push controller
42
55
  end
43
56
  end
44
57
 
45
58
  def push_password_controller
46
- lambda do
59
+ -> do
47
60
  # push controller
48
61
  end
49
62
  end
50
63
  ```
51
64
 
65
+ ### Rendering the Form
66
+
67
+ Calling #render on any form will return a hash of it's input.
68
+
69
+ Here's an example using BubbleWrap:
70
+
71
+ ``` ruby
72
+ data = form.render
73
+
74
+ p "Creating account for #{data[:email]}"
75
+
76
+ BW::HTTP.post("http://foo.bar.com/", { payload: data }) do |response|
77
+ if response.ok?
78
+ json = BW::JSON.parse(response.body.to_str)
79
+
80
+ App.alert "Thanks for signing up #{json['display_name']}!"
81
+ else
82
+ App.alert("Login failed")
83
+ end
84
+ end
85
+ ```
86
+
52
87
  ### Validation
53
88
 
54
89
  You can add validation rules to input fields.
@@ -56,17 +91,25 @@ You can add validation rules to input fields.
56
91
  The following syntax is supported:
57
92
 
58
93
  ``` ruby
59
- awesomeness_validator = lambda do |value|
94
+ awesomeness_validator = -> (value) do
60
95
  # validate awesomeness
61
96
  end
62
97
 
63
- MotionForm.form_for(view) do |form|
98
+ submit = -> do
99
+ if @form.valid?
100
+ # submit form
101
+ end
102
+ end
103
+
104
+ @form = MotionForm.form_for(view) do |form|
64
105
  form.section do |section
65
106
  section.input :name, required: true # present and not blank
66
107
  section.input :email, email: true # valid email address
67
108
  section.input :website, url: true # valid url
68
109
  section.input :age, format: /^\d+$/ # matches regex
69
110
  section.input :awesomeness, validate_with: awesomeness_validator # custom validator
111
+
112
+ section.button :submit, action: submit
70
113
  end
71
114
  end
72
115
  ```
@@ -7,6 +7,8 @@ class TextFieldCell < BaseCell
7
7
  def initWithStyle(style, reuseIdentifier: reuse_identifier)
8
8
  super.tap do |cell|
9
9
  cell.observe('ButtonCallbackWillFire', 'resign_textfield:')
10
+ cell.observe('FormWillValidate', 'resign_textfield:')
11
+ cell.observe('FormWillRender', 'resign_textfield:')
10
12
  end
11
13
  end
12
14
 
@@ -103,6 +103,8 @@ module MotionForm
103
103
  end
104
104
 
105
105
  def valid?
106
+ notification_center.postNotificationName('FormWillValidate', object: self, userInfo: nil)
107
+
106
108
  rows.select { |row| row.is_a? TextFieldRow }.all? { |row| row.valid? }
107
109
  end
108
110
 
@@ -116,6 +118,8 @@ module MotionForm
116
118
  end
117
119
 
118
120
  def render
121
+ notification_center.postNotificationName('FormWillRender', object: self, userInfo: nil)
122
+
119
123
  Hash[render_values]
120
124
  end
121
125
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devon Blandin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-17 00:00:00.000000000 Z
11
+ date: 2013-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: motion-keyboard-avoiding