effective_form_inputs 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -14
- data/app/models/effective/form_builder_inputs.rb +7 -17
- data/app/models/effective/form_input.rb +57 -28
- data/app/models/inputs/effective_date_picker/input.rb +10 -11
- data/app/models/inputs/effective_date_picker_input.rb +1 -5
- data/app/models/inputs/effective_date_time_picker/input.rb +10 -11
- data/app/models/inputs/effective_date_time_picker_input.rb +1 -5
- data/app/models/inputs/effective_select/input.rb +26 -11
- data/app/models/inputs/effective_select_input.rb +2 -5
- data/app/models/inputs/effective_static_control/input.rb +6 -7
- data/app/models/inputs/effective_static_control_input.rb +1 -5
- data/app/views/effective/style_guide/_form_default.html.haml +21 -4
- data/lib/effective_form_inputs.rb +0 -1
- data/lib/effective_form_inputs/version.rb +1 -1
- 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: 792d97f3b56394922bae94e8a202d9b92d0ac664
|
4
|
+
data.tar.gz: ec1a60a1d46296341d949c28efa63a1bc56f7c0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2f35c124ce855d1e71305d1e2a0bfd335e03b661b9d006e3d1904bcc5994e22fe6f0ee2b3ba3a487477e2d7ddee5acce99f47d8e78e725e4f1706ab2c52217b
|
7
|
+
data.tar.gz: 3cec8f1c61b3540f748b8ca422f90965009c72a9373355b164d36ef10c29a4aa2aea2514dc058aaead4804a0934fd09ddf78ba02aabd5136057b44f5c8abc340
|
data/README.md
CHANGED
@@ -77,19 +77,26 @@ As a Rails Form Helper input:
|
|
77
77
|
= f.effective_date_time_picker :updated_at
|
78
78
|
```
|
79
79
|
|
80
|
-
|
80
|
+
As a SimpleForm input:
|
81
81
|
|
82
82
|
```ruby
|
83
83
|
= simple_form_for @user do |f|
|
84
84
|
= f.input :updated_at, :as => :effective_date_time_picker
|
85
85
|
```
|
86
86
|
|
87
|
+
As a SimpleForm input without the input group (calendar glyphicon)
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
= simple_form_for @user do |f|
|
91
|
+
= f.input :updated_at, :as => :effective_date_time_picker, :input_group => false
|
92
|
+
```
|
93
|
+
|
87
94
|
### Options
|
88
95
|
|
89
96
|
The default options used to initialize this form input are as follows:
|
90
97
|
|
91
98
|
```ruby
|
92
|
-
:format => 'YYYY-MM-DD h:mm A', :sideBySide => true
|
99
|
+
:input_js => {:format => 'YYYY-MM-DD h:mm A', :sideBySide => true}
|
93
100
|
```
|
94
101
|
|
95
102
|
For a full list of options, please refer to:
|
@@ -129,19 +136,26 @@ As a Rails Form Helper input:
|
|
129
136
|
= f.effective_date_picker :started_on
|
130
137
|
```
|
131
138
|
|
132
|
-
|
139
|
+
As a SimpleForm input:
|
133
140
|
|
134
141
|
```ruby
|
135
142
|
= simple_form_for @user do |f|
|
136
143
|
= f.input :started_on, :as => :effective_date_picker
|
137
144
|
```
|
138
145
|
|
146
|
+
As a SimpleForm input without the input group (calendar glyphicon)
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
= simple_form_for @user do |f|
|
150
|
+
= f.input :updated_at, :as => :effective_date_picker, :input_group => false
|
151
|
+
```
|
152
|
+
|
139
153
|
### Options
|
140
154
|
|
141
155
|
The default options used to initialize this form input are as follows:
|
142
156
|
|
143
157
|
```ruby
|
144
|
-
:format => 'YYYY-MM-DD'
|
158
|
+
:input_js => {:format => 'YYYY-MM-DD'}
|
145
159
|
```
|
146
160
|
|
147
161
|
For a full list of options, please refer to:
|
@@ -168,7 +182,7 @@ As a Rails Form Helper input:
|
|
168
182
|
= f.effective_static_control :member_id
|
169
183
|
```
|
170
184
|
|
171
|
-
|
185
|
+
As a SimpleForm input:
|
172
186
|
|
173
187
|
```ruby
|
174
188
|
= simple_form_for @user do |f|
|
@@ -180,7 +194,6 @@ and as a SimpleForm input:
|
|
180
194
|
There are no options for this form input
|
181
195
|
|
182
196
|
|
183
|
-
|
184
197
|
## Effective Select
|
185
198
|
|
186
199
|
This custom form input is based on the following awesome project:
|
@@ -212,7 +225,7 @@ As a Rails Form Helper input:
|
|
212
225
|
= form_for @user do |f|
|
213
226
|
= f.effective_select :category, 10.times.map { |x| "Category #{x}"}
|
214
227
|
= f.effective_select :categories, 10.times.map { |x| "Category #{x}"}, :multiple => true
|
215
|
-
= f.effective_select :categories, 10.times.map { |x| "Category #{x}"}, :
|
228
|
+
= f.effective_select :categories, 10.times.map { |x| "Category #{x}"}, :tags => true
|
216
229
|
```
|
217
230
|
|
218
231
|
and as a SimpleForm input:
|
@@ -221,7 +234,7 @@ and as a SimpleForm input:
|
|
221
234
|
= simple_form_for @user do |f|
|
222
235
|
= f.input :category, :as => :effective_select, :collection => 10.times.map { |x| "Category #{x}"}
|
223
236
|
= f.input :categories, :as => :effective_select, :collection => 10.times.map { |x| "Category #{x}"}, :multiple => true
|
224
|
-
= f.input :categories, :as => :effective_select, :collection => 10.times.map { |x| "Category #{x}"}, :
|
237
|
+
= f.input :categories, :as => :effective_select, :collection => 10.times.map { |x| "Category #{x}"}, :tags => true
|
225
238
|
```
|
226
239
|
|
227
240
|
### Modes
|
@@ -235,11 +248,15 @@ Passing `:multiple => true, :tags => true` will allow multiple selections to be
|
|
235
248
|
|
236
249
|
### Options
|
237
250
|
|
238
|
-
The default options used to initialize this form input are as follows:
|
251
|
+
The default `:input_js => options` used to initialize this form input are as follows:
|
239
252
|
|
240
253
|
```ruby
|
241
|
-
:
|
254
|
+
:theme => 'bootstrap'
|
255
|
+
:minimumResultsForSearch => 6
|
242
256
|
:tokenSeparators => [',', ' ']
|
257
|
+
:width => 'style'
|
258
|
+
:placeholder => 'Please choose'
|
259
|
+
:allowClear => !(options[:multiple]) # Only display the Clear 'x' on a single selection box
|
243
260
|
```
|
244
261
|
|
245
262
|
### Interesting Available Options
|
@@ -250,7 +267,7 @@ To limit the number of items that can be selected in a multiple select box:
|
|
250
267
|
:maximumSelectionLength => 2
|
251
268
|
```
|
252
269
|
|
253
|
-
To hide the search box:
|
270
|
+
To hide the search box entirely:
|
254
271
|
|
255
272
|
```ruby
|
256
273
|
:minimumResultsForSearch => 'Infinity'
|
@@ -268,20 +285,20 @@ There is currently no support for using AJAX to load remote data. This feature
|
|
268
285
|
|
269
286
|
## Passing Options to JavaScript
|
270
287
|
|
271
|
-
All
|
288
|
+
All `:input_js => options` passed to any effective_form_input will be used to initialize the Javascript library
|
272
289
|
|
273
290
|
For example:
|
274
291
|
|
275
292
|
```ruby
|
276
293
|
= form_for @user do |f|
|
277
|
-
= f.effective_date_time_picker :updated_at, :format => 'dddd, MMMM Do YYYY', :showTodayButton => true
|
294
|
+
= f.effective_date_time_picker :updated_at, :input_js => {:format => 'dddd, MMMM Do YYYY', :showTodayButton => true}
|
278
295
|
```
|
279
296
|
|
280
297
|
or
|
281
298
|
|
282
299
|
```ruby
|
283
300
|
= simple_form_for @user do |f|
|
284
|
-
= f.input :updated_at, :as => :effective_date_time_picker, :format => 'dddd, MMMM Do YYYY', :showTodayButton => true
|
301
|
+
= f.input :updated_at, :as => :effective_date_time_picker, :input_js => {:format => 'dddd, MMMM Do YYYY', :showTodayButton => true}
|
285
302
|
```
|
286
303
|
|
287
304
|
will result in the following call to the Javascript library:
|
@@ -1,32 +1,22 @@
|
|
1
1
|
module Effective
|
2
2
|
module FormBuilderInputs
|
3
3
|
def effective_date_time_picker(method, options = {})
|
4
|
-
Inputs::EffectiveDateTimePicker::Input.new(@object, @object_name, @template, method,
|
4
|
+
Inputs::EffectiveDateTimePicker::Input.new(@object, @object_name, @template, method, options, options).to_html
|
5
5
|
end
|
6
6
|
|
7
7
|
def effective_date_picker(method, options = {})
|
8
|
-
Inputs::EffectiveDatePicker::Input.new(@object, @object_name, @template, method,
|
8
|
+
Inputs::EffectiveDatePicker::Input.new(@object, @object_name, @template, method, options, options).to_html
|
9
9
|
end
|
10
10
|
|
11
11
|
def effective_static_control(method, options = {})
|
12
|
-
Inputs::EffectiveStaticControl::Input.new(@object, @object_name, @template, method,
|
12
|
+
Inputs::EffectiveStaticControl::Input.new(@object, @object_name, @template, method, options, options).to_html
|
13
13
|
end
|
14
14
|
|
15
|
-
def effective_select(method, options_tag = nil, options = {})
|
15
|
+
def effective_select(method, options_tag = nil, options = {}, html_options = {})
|
16
16
|
options[:collection] = options_tag
|
17
|
-
options[:label_method] = :to_s
|
18
|
-
options[:value_method] = :to_s
|
19
|
-
Inputs::EffectiveSelect::Input.new(@object, @object_name, @template, method,
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def merged_input_js_options(options)
|
25
|
-
(options || {}).tap do |opts|
|
26
|
-
js_options = opts.reject { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) }
|
27
|
-
opts.reject! { |k, _| js_options.include?(k) }
|
28
|
-
opts['data-input-js-options'] = js_options if js_options.present?
|
29
|
-
end
|
17
|
+
options[:label_method] = :to_s if options[:label_method].nil?
|
18
|
+
options[:value_method] = :to_s if options[:value_method].nil?
|
19
|
+
Inputs::EffectiveSelect::Input.new(@object, @object_name, @template, method, options, html_options).to_html
|
30
20
|
end
|
31
21
|
end
|
32
22
|
end
|
@@ -1,12 +1,35 @@
|
|
1
1
|
module Effective
|
2
2
|
class FormInput
|
3
3
|
|
4
|
-
def initialize(object, object_name, template, method, opts)
|
4
|
+
def initialize(object, object_name, template, method, opts, html_opts = {})
|
5
5
|
@object = object
|
6
6
|
@object_name = object_name
|
7
7
|
@template = template
|
8
8
|
@method = method
|
9
|
-
|
9
|
+
|
10
|
+
# Initialize 3 options Hashes: @opts, @html_opts, and @js_opts
|
11
|
+
@js_opts = opts.delete(:input_js).presence || {}
|
12
|
+
@html_opts = html_opts.presence || opts.delete(:input_html) || {}
|
13
|
+
@opts = opts.presence || {}
|
14
|
+
|
15
|
+
# Copy the following keys from options to html_options
|
16
|
+
# To deal with SimpleForm being simple
|
17
|
+
[:class, :readonly, :pattern, :disabled, :maxlength].each do |key|
|
18
|
+
if !html_opts.key?(key) && @opts.key?(key)
|
19
|
+
@html_opts[key] = @opts[:key] if @opts[:key]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Reverse merge in the defaults, so the current values take precedence over defaults
|
24
|
+
@js_opts.reverse_merge!((default_input_js || {}))
|
25
|
+
@html_opts.reverse_merge!((default_input_html || {}).except(:class))
|
26
|
+
@opts.reverse_merge!((default_options || {}))
|
27
|
+
|
28
|
+
# Take special procedure to ensure that @html_opts[:class] is an Array, and the proper merged values
|
29
|
+
@html_opts[:class] = (arrayize_html_class_key(@html_opts[:class]) + arrayize_html_class_key(default_input_html)).compact.uniq
|
30
|
+
|
31
|
+
# Set the value to avoid options craziness
|
32
|
+
@value = (@opts.delete(:value) || @html_opts.delete(:value) || (@object.send(@method) if @object.respond_to?(@method)))
|
10
33
|
end
|
11
34
|
|
12
35
|
def field_name
|
@@ -14,43 +37,49 @@ module Effective
|
|
14
37
|
end
|
15
38
|
|
16
39
|
def value
|
17
|
-
|
40
|
+
@value
|
18
41
|
end
|
19
42
|
|
20
|
-
|
21
|
-
|
43
|
+
# Override these methods to change any options around
|
44
|
+
# tag_options reads html_options and js_options
|
45
|
+
def options; @opts end # All options passed to the FormInput, merged with defaults
|
46
|
+
def html_options; @html_opts end # All :input_html => options, merged with defaults. Could be everything (same as options) if coming from FormBuilder.
|
47
|
+
def js_options; @js_opts end # All :input_js => options, merged with defaults
|
22
48
|
|
23
|
-
|
24
|
-
@form_field_options ||= (
|
25
|
-
(@opts || {}).tap do |options|
|
26
|
-
options['data-input-js-options'] = {} unless options['data-input-js-options'].kind_of?(Hash)
|
27
|
-
merge_class_options!(options)
|
49
|
+
protected
|
28
50
|
|
29
|
-
|
51
|
+
# Hook methods for an inheritting class to apply defaults
|
52
|
+
def default_options; {} end # All options passed to FormInput
|
53
|
+
def default_input_html; {} end # To merge with any :input_html => options
|
54
|
+
def default_input_js; {} end # to merge with any :input_js => options
|
30
55
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
56
|
+
# This is what we want to send to a content_tag, text_area_tag, or whatever actual input we use
|
57
|
+
# It serializes any js_options into JSON format
|
58
|
+
# And turns html_options[:class] back into a string
|
59
|
+
def tag_options
|
60
|
+
html_options().tap do |html_options|
|
61
|
+
html_options['data-input-js-options'] = (JSON.generate(js_options) rescue {})
|
62
|
+
html_options[:class] = html_options[:class].join(' ')
|
63
|
+
end
|
35
64
|
end
|
36
65
|
|
37
66
|
private
|
38
67
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
68
|
+
# I'm passed something...I don't know what it is, but it needs to be an Array
|
69
|
+
def arrayize_html_class_key(something)
|
70
|
+
case something
|
71
|
+
when Hash
|
72
|
+
arrayize_html_class_key(something[:class])
|
73
|
+
when Array
|
74
|
+
something.compact.map(&:to_s)
|
75
|
+
when String
|
76
|
+
something.split(' ')
|
77
|
+
when Symbol
|
78
|
+
[something.to_s]
|
79
|
+
else
|
80
|
+
[]
|
48
81
|
end
|
49
82
|
end
|
50
83
|
|
51
|
-
def merge_input_js_options!(options)
|
52
|
-
options['data-input-js-options'] = JSON.generate((default_input_js_options || {}).merge(options['data-input-js-options'] || {})) rescue {}
|
53
|
-
end
|
54
|
-
|
55
84
|
end
|
56
85
|
end
|
@@ -3,35 +3,34 @@ module Inputs
|
|
3
3
|
class Input < Effective::FormInput
|
4
4
|
delegate :content_tag, :text_field_tag, :to => :@template
|
5
5
|
|
6
|
-
def
|
6
|
+
def default_input_js
|
7
7
|
{:format => 'YYYY-MM-DD'}
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def default_input_html
|
11
|
+
{class: 'effective_date_picker date'}
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_html
|
15
|
-
if options
|
16
|
-
return text_field_tag(field_name, value,
|
15
|
+
if options[:input_group] == false
|
16
|
+
return text_field_tag(field_name, value, tag_options)
|
17
17
|
end
|
18
18
|
|
19
19
|
content_tag(:div, :class => 'input-group') do
|
20
20
|
content_tag(:span, :class => 'input-group-addon') do
|
21
21
|
content_tag(:i, '', :class => 'glyphicon glyphicon-calendar').html_safe
|
22
22
|
end +
|
23
|
-
text_field_tag(field_name, value,
|
23
|
+
text_field_tag(field_name, value, tag_options)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
super do |
|
29
|
-
|
30
|
-
|
27
|
+
def html_options
|
28
|
+
super.tap do |html_options|
|
29
|
+
if js_options[:format] == default_input_js[:format] # Unless someone changed from the default
|
30
|
+
html_options[:pattern] = '\d{4}-\d{2}-\d{2}' # Match default pattern defined above
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
@@ -5,11 +5,7 @@ if defined?(SimpleForm)
|
|
5
5
|
|
6
6
|
class EffectiveDatePickerInput < SimpleForm::Inputs::StringInput
|
7
7
|
def input(wrapper_options = nil)
|
8
|
-
|
9
|
-
options.merge!(input_options.select { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) })
|
10
|
-
options['data-input-js-options'] = input_options.reject { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) }
|
11
|
-
|
12
|
-
Inputs::EffectiveDatePicker::Input.new(object, object_name, template, attribute_name, options).to_html
|
8
|
+
Inputs::EffectiveDatePicker::Input.new(object, object_name, template, attribute_name, input_options, (merge_wrapper_options(input_html_options, wrapper_options) || {})).to_html
|
13
9
|
end
|
14
10
|
end
|
15
11
|
|
@@ -3,35 +3,34 @@ module Inputs
|
|
3
3
|
class Input < Effective::FormInput
|
4
4
|
delegate :content_tag, :text_field_tag, :to => :@template
|
5
5
|
|
6
|
-
def
|
6
|
+
def default_input_js
|
7
7
|
{:format => 'YYYY-MM-DD h:mm A', :sideBySide => true}
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def default_input_html
|
11
|
+
{class: 'effective_date_time_picker datetime'}
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_html
|
15
|
-
if options
|
16
|
-
return text_field_tag(field_name, value,
|
15
|
+
if options[:input_group] == false
|
16
|
+
return text_field_tag(field_name, value, tag_options)
|
17
17
|
end
|
18
18
|
|
19
19
|
content_tag(:div, :class => 'input-group') do
|
20
20
|
content_tag(:span, :class => 'input-group-addon') do
|
21
21
|
content_tag(:i, '', :class => 'glyphicon glyphicon-calendar').html_safe
|
22
22
|
end +
|
23
|
-
text_field_tag(field_name, value,
|
23
|
+
text_field_tag(field_name, value, tag_options)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
super do |
|
29
|
-
|
30
|
-
|
27
|
+
def html_options
|
28
|
+
super.tap do |html_options|
|
29
|
+
if js_options[:format] == default_input_js[:format] # Unless someone changed from the default
|
30
|
+
html_options[:pattern] = '\d{4}-\d{2}-\d{2} \d+:\d{2} [A-Z]{2}' # Match default pattern defined above
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
@@ -5,11 +5,7 @@ if defined?(SimpleForm)
|
|
5
5
|
|
6
6
|
class EffectiveDateTimePickerInput < SimpleForm::Inputs::StringInput
|
7
7
|
def input(wrapper_options = nil)
|
8
|
-
|
9
|
-
options.merge!(input_options.select { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) })
|
10
|
-
options['data-input-js-options'] = input_options.reject { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) }
|
11
|
-
|
12
|
-
Inputs::EffectiveDateTimePicker::Input.new(object, object_name, template, attribute_name, options).to_html
|
8
|
+
Inputs::EffectiveDateTimePicker::Input.new(object, object_name, template, attribute_name, input_options, (merge_wrapper_options(input_html_options, wrapper_options) || {})).to_html
|
13
9
|
end
|
14
10
|
end
|
15
11
|
|
@@ -3,28 +3,43 @@ module Inputs
|
|
3
3
|
class Input < Effective::FormInput
|
4
4
|
delegate :collection_select, :to => :@template
|
5
5
|
|
6
|
-
def
|
7
|
-
{:
|
6
|
+
def default_options
|
7
|
+
{:label_method => :to_s, :value_method => :to_s}
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
[:
|
10
|
+
def default_input_js
|
11
|
+
{theme: 'bootstrap', minimumResultsForSearch: 6, tokenSeparators: [',', ' '], width: 'style', placeholder: 'Please choose'}
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_input_html
|
15
|
+
{class: 'effective_select', placeholder: 'Please choose'}
|
12
16
|
end
|
13
17
|
|
14
18
|
def to_html
|
15
|
-
collection_select(@object_name, @method, options
|
19
|
+
collection_select(@object_name, @method, options[:collection], options[:label_method], options[:value_method], options, tag_options)
|
16
20
|
end
|
17
21
|
|
18
22
|
def options
|
19
|
-
super do |options|
|
20
|
-
options[:
|
23
|
+
super().tap do |options|
|
24
|
+
options[:selected] = value if value
|
25
|
+
|
26
|
+
options[:multiple] = true if (options[:tags] == true)
|
27
|
+
options[:include_blank] = (options[:multiple] != true)
|
28
|
+
end
|
29
|
+
end
|
21
30
|
|
22
|
-
|
23
|
-
|
24
|
-
|
31
|
+
def html_options
|
32
|
+
super().tap do |html_options|
|
33
|
+
html_options[:multiple] = options[:multiple]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def js_options
|
38
|
+
super().tap do |js_options|
|
39
|
+
js_options[:allowClear] = (options[:multiple] != true)
|
40
|
+
js_options[:tags] = (options[:tags] == true)
|
25
41
|
end
|
26
42
|
end
|
27
43
|
end
|
28
44
|
end
|
29
45
|
end
|
30
|
-
|
@@ -7,14 +7,11 @@ if defined?(SimpleForm)
|
|
7
7
|
def input(wrapper_options = nil)
|
8
8
|
label_method, value_method = detect_collection_methods
|
9
9
|
|
10
|
-
options = merge_wrapper_options(input_html_options, wrapper_options) || {}
|
11
|
-
options.merge!(input_options.select { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) })
|
12
|
-
options['data-input-js-options'] = input_options.reject { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) }
|
13
|
-
|
14
10
|
options[:collection] = collection
|
15
11
|
options[:label_method] = label_method
|
16
12
|
options[:value_method] = value_method
|
17
|
-
|
13
|
+
|
14
|
+
Inputs::EffectiveSelect::Input.new(object, object_name, template, attribute_name, input_options, (merge_wrapper_options(input_html_options, wrapper_options) || {})).to_html
|
18
15
|
end
|
19
16
|
end
|
20
17
|
|
@@ -3,18 +3,17 @@ module Inputs
|
|
3
3
|
class Input < Effective::FormInput
|
4
4
|
delegate :content_tag, :to => :@template
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def default_input_html
|
7
|
+
{class: 'form-control-static'}
|
8
8
|
end
|
9
9
|
|
10
10
|
def to_html
|
11
|
-
content_tag(:p, value,
|
11
|
+
content_tag(:p, value, tag_options)
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
super do |
|
16
|
-
|
17
|
-
options[:class].delete!('form-control') if options[:class].kind_of?(String)
|
14
|
+
def html_options
|
15
|
+
super.tap do |html_options|
|
16
|
+
html_options[:class].delete('form-control')
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
@@ -5,11 +5,7 @@ if defined?(SimpleForm)
|
|
5
5
|
|
6
6
|
class EffectiveStaticControlInput < SimpleForm::Inputs::StringInput
|
7
7
|
def input(wrapper_options = nil)
|
8
|
-
|
9
|
-
options.merge!(input_options.select { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) })
|
10
|
-
options['data-input-js-options'] = input_options.reject { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) }
|
11
|
-
|
12
|
-
Inputs::EffectiveStaticControl::Input.new(object, object_name, template, attribute_name, options).to_html
|
8
|
+
Inputs::EffectiveStaticControl::Input.new(object, object_name, template, attribute_name, input_options, (merge_wrapper_options(input_html_options, wrapper_options) || {})).to_html
|
13
9
|
end
|
14
10
|
end
|
15
11
|
|
@@ -1,7 +1,24 @@
|
|
1
1
|
/ this gives me a mechanism to test the inputs easily on a site with effective style_guide installed
|
2
2
|
|
3
3
|
= form_for Effective::StyleGuide.new(:category => 'Category 2'), :url => '/' do |f|
|
4
|
-
= f.
|
5
|
-
= f.effective_date_picker :updated_at
|
6
|
-
|
7
|
-
= f.
|
4
|
+
/ = f.date_field :updated_at, :class => 'my-class'
|
5
|
+
/ = f.effective_date_picker :updated_at, :class => 'my-class'
|
6
|
+
/ %hr
|
7
|
+
/ = f.datetime_field :updated_at
|
8
|
+
/ = f.effective_date_time_picker :updated_at
|
9
|
+
/ %hr
|
10
|
+
/ = f.select :category, 10.times.map { |x| "Category #{x}"}, {:include_blank => true}, {:class => 'my-class'}
|
11
|
+
/ = f.effective_select :category, 10.times.map { |x| "Category #{x}"}, {:include_blank => true}, {:class => 'my-class'}
|
12
|
+
/ %hr
|
13
|
+
/ = f.select :category, 10.times.map { |x| "Category #{x}"}, {:multiple => true}, {:class => 'my-class'}
|
14
|
+
/ = f.effective_select :category, 10.times.map { |x| "Category #{x}"}, {:multiple => true}, {:class => 'my-class'}
|
15
|
+
/ %hr
|
16
|
+
/ = f.effective_static_control :static_text, :value => 'this is static control value', :class => 'my-class'
|
17
|
+
|
18
|
+
|
19
|
+
/= f.text_field :title, :class => 'my-text-field'
|
20
|
+
/= f.datetime_field :updated_at, :class => 'my-updated-at-class', :something => 'cool'
|
21
|
+
/= f.effective_date_time_picker :updated_at, :class => 'my-updated-at-class', :something => 'cool'
|
22
|
+
|
23
|
+
/= f.select :category, 10.times.map { |x| "Category #{x}"}, {:include_blank => true}, {:class => 'myclass'}
|
24
|
+
/= f.effective_select :category, 10.times.map { |x| "Category #{x}"}, {:include_blank => false}, {:class => 'myclass'}
|
@@ -2,5 +2,4 @@ require "effective_form_inputs/engine"
|
|
2
2
|
require "effective_form_inputs/version"
|
3
3
|
|
4
4
|
module EffectiveFormInputs
|
5
|
-
REJECTED_INPUT_JS_OPTIONS = [:as, :hint, :error, :readonly, :disabled, :required, :label, :inline_label, :prompt, :min_max, :maxlength, :pattern, :input_html, :wrapper_html, :error_html, :id, :wrapper, :collection, :multiple, :include_blank, :label_method, :value_method, :input_group]
|
6
5
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_form_inputs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|