ProMotion-XLForm 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +50 -11
- data/lib/ProMotion-XLForm.rb +3 -0
- data/lib/ProMotion/XLForm/validators/regex_validator.rb +20 -0
- data/lib/ProMotion/XLForm/validators/url_validator.rb +7 -0
- data/lib/ProMotion/XLForm/validators/validator.rb +18 -0
- data/lib/ProMotion/XLForm/xl_form.rb +34 -0
- data/lib/ProMotion/XLForm/xl_form_screen.rb +54 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55924720d004b7e0a3e9bf60576b3803ef96cfbb
|
4
|
+
data.tar.gz: abf8c29c048a7db559d0decee91fdde5adaaf616
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89a3c12aa9d571911681e0b54a85a91602218c5534c3c7fceaea08d4dadddf691957478cfd6a4dad4af0eb826556118f328b75c88b19f109b7b015393aac4ff5
|
7
|
+
data.tar.gz: fe7a80cedbebf1ecfcf1c540744f2bb5519ae978ea136c5d4e659d72a2df18c0a15c661abd399cd86faedf011d332a01b429dd66cfd0fa7cc14bc9c792991bd7
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ ProMotion-XLForm provides a PM::XLFormScreen for [ProMotion](https://github.com/
|
|
5
5
|
## Warning
|
6
6
|
This gem is currently in very early-stage. Use it at your own risk :)
|
7
7
|
|
8
|
-
[![Build Status](https://travis-ci.org/bmichotte/ProMotion-XLForm.svg?branch=master)](https://travis-ci.org/bmichotte/ProMotion-XLForm)
|
8
|
+
[![Build Status](https://travis-ci.org/bmichotte/ProMotion-XLForm.svg?branch=master)](https://travis-ci.org/bmichotte/ProMotion-XLForm) [![Gem Version](https://badge.fury.io/rb/ProMotion-XLForm.svg)](http://badge.fury.io/rb/ProMotion-XLForm)
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
@@ -169,18 +169,23 @@ You can create a custom _subform_ with a few options
|
|
169
169
|
|
170
170
|
```ruby
|
171
171
|
{
|
172
|
-
title:
|
173
|
-
name: :custom,
|
172
|
+
title: 'Custom section',
|
174
173
|
cells: [
|
175
174
|
{
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
175
|
+
title: 'Custom',
|
176
|
+
name: :custom,
|
177
|
+
cells: [
|
178
|
+
{
|
179
|
+
title: 'Some text',
|
180
|
+
name: :some_text,
|
181
|
+
type: :text
|
182
|
+
},
|
183
|
+
{
|
184
|
+
title: 'Other text',
|
185
|
+
name: :some_other_text,
|
186
|
+
type: :text
|
187
|
+
}
|
188
|
+
]
|
184
189
|
}
|
185
190
|
]
|
186
191
|
}
|
@@ -211,6 +216,40 @@ end
|
|
211
216
|
|
212
217
|
For a more advanced custom selector, you can set `view_controller_class:`. See [XLForm documentation](https://github.com/xmartlabs/XLForm/#custom-selectors---selector-row-with-a-custom-selector-view-controller) for more informations.
|
213
218
|
|
219
|
+
### Validators
|
220
|
+
|
221
|
+
You can add validators to cells.
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
{
|
225
|
+
title: 'Email',
|
226
|
+
name: :email,
|
227
|
+
type: :email,
|
228
|
+
required: true,
|
229
|
+
validators: {
|
230
|
+
email: true
|
231
|
+
}
|
232
|
+
}
|
233
|
+
```
|
234
|
+
|
235
|
+
`:email` and `:url` are available out of the box, as well as `:regex`. You will have to provide a valid regex and a message.
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
{
|
239
|
+
title: 'Only letters',
|
240
|
+
name: :letters,
|
241
|
+
type: :text,
|
242
|
+
required: true,
|
243
|
+
validators: {
|
244
|
+
regex: { regex: /^[a-zA-Z]+$/, message: "Only letters please !" }
|
245
|
+
}
|
246
|
+
}
|
247
|
+
```
|
248
|
+
|
249
|
+
Finally, you can provide a PM::Validator with a `valid?(cell)` method.
|
250
|
+
|
251
|
+
|
252
|
+
|
214
253
|
## Todo
|
215
254
|
- Validations
|
216
255
|
- Tests
|
data/lib/ProMotion-XLForm.rb
CHANGED
@@ -15,6 +15,9 @@ Motion::Project::App.setup do |app|
|
|
15
15
|
app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_sub_form_screen.rb")
|
16
16
|
app.files << File.join(lib_dir_path, "ProMotion/XLForm/xl_form_patch.rb")
|
17
17
|
app.files << File.join(lib_dir_path, "ProMotion/XLForm/value_transformer.rb")
|
18
|
+
app.files << File.join(lib_dir_path, "ProMotion/XLForm/validators/validator.rb")
|
19
|
+
app.files << File.join(lib_dir_path, "ProMotion/XLForm/validators/url_validator.rb")
|
20
|
+
app.files << File.join(lib_dir_path, "ProMotion/XLForm/validators/regex_validator.rb")
|
18
21
|
|
19
22
|
app.pods do
|
20
23
|
pod 'XLForm', '~> 3.0.0'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ProMotion
|
2
|
+
class RegexValidator < ProMotion::Validator
|
3
|
+
attr_accessor :regex
|
4
|
+
|
5
|
+
def initialize(message, regex)
|
6
|
+
@message = message
|
7
|
+
@regex = regex
|
8
|
+
end
|
9
|
+
|
10
|
+
def valid?(row)
|
11
|
+
return nil if row.nil? or row.value.nil? or !row.value.is_a?(String)
|
12
|
+
|
13
|
+
!@regex.match(row.value).nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.validator(message, regex)
|
17
|
+
ProMotion::RegexValidator.new(message, regex)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ProMotion
|
2
|
+
class Validator
|
3
|
+
attr_accessor :message
|
4
|
+
|
5
|
+
def isValid(row)
|
6
|
+
is_valid = nil
|
7
|
+
is_valid = valid?(row) if self.respond_to?(:valid?)
|
8
|
+
|
9
|
+
return nil if is_valid.nil?
|
10
|
+
XLFormValidationStatus.formValidationStatusWithMsg(@message, status: is_valid, rowDescriptor: row)
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid?(row)
|
14
|
+
mp "You have to override valid?", force_color: :red
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -129,6 +129,40 @@ module ProMotion
|
|
129
129
|
|
130
130
|
cell.disabled = !cell_data[:enabled] if cell_data[:enabled]
|
131
131
|
|
132
|
+
# validators
|
133
|
+
if cell_data[:validators]
|
134
|
+
validators = cell_data[:validators]
|
135
|
+
validators.each do |key, value|
|
136
|
+
validator = case key
|
137
|
+
when :email
|
138
|
+
XLFormValidator.emailValidator
|
139
|
+
when :regex
|
140
|
+
regex = value[:regex]
|
141
|
+
if regex.is_a?(String)
|
142
|
+
XLFormRegexValidator.formRegexValidatorWithMsg(value[:message], regex: regex)
|
143
|
+
elsif regex.is_a?(Regexp)
|
144
|
+
ProMotion::RegexValidator.validator(value[:message], regex)
|
145
|
+
else
|
146
|
+
mp "Invalid regex : #{regex.inspect}. Please provides a Regexp or a String", force_color: :red
|
147
|
+
nil
|
148
|
+
end
|
149
|
+
when :url
|
150
|
+
ProMotion::UrlValidator.validator
|
151
|
+
else
|
152
|
+
if value.is_a?(ProMotion::Validator) or value.respond_to?(:isValid)
|
153
|
+
value
|
154
|
+
else
|
155
|
+
mp "Invalid validator : #{key}", force_color: :red
|
156
|
+
nil
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
if validator
|
161
|
+
cell.addValidator(validator)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
132
166
|
section.addFormRow(cell)
|
133
167
|
|
134
168
|
# multi sections
|
@@ -116,6 +116,60 @@ module ProMotion
|
|
116
116
|
reloadFormRow(cell)
|
117
117
|
end
|
118
118
|
|
119
|
+
def add_cell(cell, opts={})
|
120
|
+
if opts[:before]
|
121
|
+
row = opts[:before]
|
122
|
+
if row.is_a?(Symbol)
|
123
|
+
row = cell_with_tag(row)
|
124
|
+
end
|
125
|
+
self.form.addFormRow(cell, beforeRow: row)
|
126
|
+
elsif opts[:after]
|
127
|
+
row = opts[:after]
|
128
|
+
if row.is_a?(Symbol)
|
129
|
+
row = cell_with_tag(row)
|
130
|
+
end
|
131
|
+
self.form.addFormRow(cell, afterRow: row)
|
132
|
+
else
|
133
|
+
mp "Don't know where to add cell, please provides either :before or :after", force_color: :red
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def add_section(section, opts={})
|
138
|
+
if opts[:index]
|
139
|
+
self.form.addFormSection(section, atIndex: opts[:index])
|
140
|
+
elsif opts[:after]
|
141
|
+
self.form.addFormSection(section, afterSection: opts[:after])
|
142
|
+
else
|
143
|
+
self.form.addFormSection(section)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def remove_section!(section_or_index)
|
148
|
+
if section_or_index.is_a?(XLFormSectionDescriptor)
|
149
|
+
self.form.removeFormSection(section_or_index)
|
150
|
+
else
|
151
|
+
self.form.removeFormSectionAtIndex(section_or_index)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def remove_cell!(cell)
|
156
|
+
if cell.is_a?(Symbol)
|
157
|
+
self.form.removeFormRowWithTag(cell.to_s)
|
158
|
+
elsif cell.is_a?(String)
|
159
|
+
self.form.removeFormRowWithTag(cell)
|
160
|
+
else
|
161
|
+
self.form.removeFormRow(cell)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def enabled=(value)
|
166
|
+
self.form.disabled = !value
|
167
|
+
end
|
168
|
+
|
169
|
+
def enabled?
|
170
|
+
!self.form.isDisabled
|
171
|
+
end
|
172
|
+
|
119
173
|
protected
|
120
174
|
def on_cancel(_)
|
121
175
|
form_options = self.class.get_form_options
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ProMotion-XLForm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Michotte
|
@@ -76,6 +76,9 @@ files:
|
|
76
76
|
- README.md
|
77
77
|
- lib/ProMotion-XLForm.rb
|
78
78
|
- lib/ProMotion/XLForm/cells/xl_form_image_selector_cell.rb
|
79
|
+
- lib/ProMotion/XLForm/validators/regex_validator.rb
|
80
|
+
- lib/ProMotion/XLForm/validators/url_validator.rb
|
81
|
+
- lib/ProMotion/XLForm/validators/validator.rb
|
79
82
|
- lib/ProMotion/XLForm/value_transformer.rb
|
80
83
|
- lib/ProMotion/XLForm/xl_form.rb
|
81
84
|
- lib/ProMotion/XLForm/xl_form_class_methods.rb
|