motion-form 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +47 -4
- data/lib/project/cells/text_field_cell.rb +2 -0
- data/lib/project/form/base.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f2148d8f02ba7ad77a2b2f268a3eae119193625
|
4
|
+
data.tar.gz: 3051d088e431e7b8dc89a1af6cba627cfa7b29a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
53
|
+
-> do
|
41
54
|
# push controller
|
42
55
|
end
|
43
56
|
end
|
44
57
|
|
45
58
|
def push_password_controller
|
46
|
-
|
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 =
|
94
|
+
awesomeness_validator = -> (value) do
|
60
95
|
# validate awesomeness
|
61
96
|
end
|
62
97
|
|
63
|
-
|
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
|
|
data/lib/project/form/base.rb
CHANGED
@@ -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
|
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-
|
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
|