effective_form_inputs 0.1.2 → 0.2.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 +81 -4
- data/app/assets/javascripts/effective_date_picker/initialize.js.coffee +12 -0
- data/app/assets/javascripts/effective_date_picker/input.js +3 -0
- data/app/assets/javascripts/effective_form_inputs.js +1 -0
- data/app/assets/stylesheets/effective_date_picker/input.scss +1 -0
- data/{lib/effective_form_inputs/form_inputs.rb → app/models/effective/form_builder_inputs.rb} +7 -3
- data/app/models/effective/{form_input_field.rb → form_input.rb} +1 -1
- data/app/models/inputs/effective_date_picker/input.rb +34 -0
- data/app/models/inputs/effective_date_picker_input.rb +15 -0
- data/app/models/inputs/effective_date_time_picker/{field.rb → input.rb} +1 -1
- data/app/models/inputs/effective_date_time_picker_input.rb +15 -0
- data/app/views/effective/style_guide/_form_default.html.haml +1 -0
- data/lib/effective_form_inputs.rb +0 -1
- data/lib/effective_form_inputs/engine.rb +1 -9
- data/lib/effective_form_inputs/version.rb +1 -1
- metadata +11 -6
- data/app/models/inputs/effective_date_time_picker/effective_date_time_picker_input.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11b76163fed4145fb5cd13cb4ada4c849d79b827
|
4
|
+
data.tar.gz: eb0ec003718c67485121f6552104012f9aee6893
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 177afe359f6345cbeaeaa18bcdf89ff0ba29c00b226cf6e39c53c934e7d773c177ba7895e28bd95bead643ec0e751ca7c54f68a178b52b3c3f4b1e87b68a9896
|
7
|
+
data.tar.gz: d32d328529515106b360f3986aa0474d2689e10498dff171c9e3a319e1dfe3d7a6ee210eeb7680c9baa6c778eff5b04635b251432001821ef06205f5ce5e6f6a
|
data/README.md
CHANGED
@@ -84,15 +84,64 @@ and as a SimpleForm input:
|
|
84
84
|
= f.input :updated_at, :as => :effective_date_time_picker
|
85
85
|
```
|
86
86
|
|
87
|
-
###
|
87
|
+
### Options
|
88
88
|
|
89
|
-
|
89
|
+
The default options used to initialize this form input are as follows:
|
90
90
|
|
91
|
-
|
91
|
+
```ruby
|
92
|
+
:format => 'YYYY-MM-DD h:mm A', :sideBySide => true
|
93
|
+
```
|
94
|
+
|
95
|
+
For a full list of options, please refer to:
|
96
|
+
|
97
|
+
http://eonasdan.github.io/bootstrap-datetimepicker/Options/
|
98
|
+
|
99
|
+
|
100
|
+
## Bootstrap3 DatePicker
|
101
|
+
|
102
|
+
This custom form input is based on the following awesome project:
|
103
|
+
|
104
|
+
Bootstrap 3 Datepicker (https://github.com/Eonasdan/bootstrap-datetimepicker)
|
105
|
+
|
106
|
+
|
107
|
+
### Installation
|
108
|
+
|
109
|
+
If you've already installed the 'All Form Inputs' assets (see above), there are no additional installation steps.
|
110
|
+
|
111
|
+
To install this form input individually, add the following to your application.js:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
//= require effective_date_picker/input
|
115
|
+
```
|
116
|
+
|
117
|
+
and add the following to your application.css:
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
*= require effective_date_picker/input
|
121
|
+
```
|
122
|
+
|
123
|
+
### Usage
|
124
|
+
|
125
|
+
As a Rails Form Helper input:
|
92
126
|
|
93
127
|
```ruby
|
94
128
|
= form_for @user do |f|
|
95
|
-
= f.
|
129
|
+
= f.effective_date_picker :started_on
|
130
|
+
```
|
131
|
+
|
132
|
+
and as a SimpleForm input:
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
= simple_form_for @user do |f|
|
136
|
+
= f.input :started_on, :as => :effective_date_picker
|
137
|
+
```
|
138
|
+
|
139
|
+
### Options
|
140
|
+
|
141
|
+
The default options used to initialize this form input are as follows:
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
:format => 'YYYY-MM-DD'
|
96
145
|
```
|
97
146
|
|
98
147
|
For a full list of options, please refer to:
|
@@ -100,6 +149,34 @@ For a full list of options, please refer to:
|
|
100
149
|
http://eonasdan.github.io/bootstrap-datetimepicker/Options/
|
101
150
|
|
102
151
|
|
152
|
+
## Passing Options to JavaScript
|
153
|
+
|
154
|
+
All appropriate options passed to any effective_form_input will be used to initialize the Javascript library
|
155
|
+
|
156
|
+
For example:
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
= form_for @user do |f|
|
160
|
+
= f.effective_date_time_picker :updated_at, :format => 'dddd, MMMM Do YYYY', :showTodayButton => true
|
161
|
+
```
|
162
|
+
|
163
|
+
or
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
= simple_form_for @user do |f|
|
167
|
+
= f.input :updated_at, :as => :effective_date_time_picker, :format => 'dddd, MMMM Do YYYY', :showTodayButton => true
|
168
|
+
```
|
169
|
+
|
170
|
+
will result in the following call to the Javascript library:
|
171
|
+
|
172
|
+
```coffee
|
173
|
+
$('input.effective_date_time_picker').datetimepicker
|
174
|
+
format: 'dddd, MMMM Do YYYY',
|
175
|
+
showTodayButton: true
|
176
|
+
```
|
177
|
+
|
178
|
+
Any option not recognized as a Rails Form Helper or SimpleForm option will be passed in this way to Javascript.
|
179
|
+
|
103
180
|
## License
|
104
181
|
|
105
182
|
MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# http://eonasdan.github.io/bootstrap-datetimepicker/Options/
|
2
|
+
|
3
|
+
initialize = ->
|
4
|
+
$('input.effective_date_picker:not(.initialized)').each (i, element) ->
|
5
|
+
element = $(element)
|
6
|
+
options = element.data('input-js-options') || {}
|
7
|
+
|
8
|
+
element.addClass('initialized').datetimepicker(options)
|
9
|
+
|
10
|
+
$ -> initialize()
|
11
|
+
$(document).on 'page:change', -> initialize()
|
12
|
+
$(document).on 'cocoon:after-insert', -> initialize()
|
@@ -0,0 +1 @@
|
|
1
|
+
@import '../effective_date_time_picker/bootstrap-datetimepicker';
|
data/{lib/effective_form_inputs/form_inputs.rb → app/models/effective/form_builder_inputs.rb}
RENAMED
@@ -1,7 +1,11 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module Effective
|
2
|
+
module FormBuilderInputs
|
3
3
|
def effective_date_time_picker(method, options = {})
|
4
|
-
Inputs::EffectiveDateTimePicker::
|
4
|
+
Inputs::EffectiveDateTimePicker::Input.new(@object, @object_name, @template, method, merged_input_js_options(options)).to_html
|
5
|
+
end
|
6
|
+
|
7
|
+
def effective_date_picker(method, options = {})
|
8
|
+
Inputs::EffectiveDatePicker::Input.new(@object, @object_name, @template, method, merged_input_js_options(options)).to_html
|
5
9
|
end
|
6
10
|
|
7
11
|
private
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Inputs
|
2
|
+
module EffectiveDatePicker
|
3
|
+
class Input < Effective::FormInput
|
4
|
+
delegate :content_tag, :text_field_tag, :to => :@template
|
5
|
+
|
6
|
+
def default_input_js_options
|
7
|
+
{:format => 'YYYY-MM-DD'}
|
8
|
+
end
|
9
|
+
|
10
|
+
def default_input_classes
|
11
|
+
[:effective_date_picker, :date]
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_html
|
15
|
+
content_tag(:div, :class => 'input-group') do
|
16
|
+
content_tag(:span, :class => 'input-group-addon') do
|
17
|
+
content_tag(:i, '', :class => 'glyphicon glyphicon-calendar').html_safe
|
18
|
+
end +
|
19
|
+
text_field_tag(field_name, value, options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def options
|
24
|
+
super do |options|
|
25
|
+
unless options['data-input-js-options'][:format].present?
|
26
|
+
options[:pattern] = '\d{4}-\d{2}-\d{2}'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# = simple_form_for @thing do |f|
|
2
|
+
# = f.input :updated_at, :as => :effective_date_picker
|
3
|
+
|
4
|
+
if defined?(SimpleForm)
|
5
|
+
|
6
|
+
class EffectiveDatePickerInput < SimpleForm::Inputs::StringInput
|
7
|
+
def input(wrapper_options = nil)
|
8
|
+
options = merge_wrapper_options(input_html_options, wrapper_options) || {}
|
9
|
+
options['data-input-js-options'] = input_options.reject { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) }
|
10
|
+
|
11
|
+
Inputs::EffectiveDatePicker::Input.new(object, object_name, template, attribute_name, options).to_html
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# = simple_form_for @thing do |f|
|
2
|
+
# = f.input :updated_at, :as => :effective_date_time_picker
|
3
|
+
|
4
|
+
if defined?(SimpleForm)
|
5
|
+
|
6
|
+
class EffectiveDateTimePickerInput < SimpleForm::Inputs::StringInput
|
7
|
+
def input(wrapper_options = nil)
|
8
|
+
options = merge_wrapper_options(input_html_options, wrapper_options) || {}
|
9
|
+
options['data-input-js-options'] = input_options.reject { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) }
|
10
|
+
|
11
|
+
Inputs::EffectiveDateTimePicker::Input.new(object, object_name, template, attribute_name, options).to_html
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -6,15 +6,7 @@ module EffectiveFormInputs
|
|
6
6
|
|
7
7
|
initializer 'effective_orders.action_view' do |app|
|
8
8
|
ActiveSupport.on_load :action_view do
|
9
|
-
ActionView::Helpers::FormBuilder.send(:include,
|
10
|
-
|
11
|
-
# Going to have to add each custom namespace to SimpleForm
|
12
|
-
if defined?(SimpleForm)
|
13
|
-
SimpleForm.setup do |config|
|
14
|
-
config.custom_inputs_namespaces << 'EffectiveDateTimePicker'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
9
|
+
ActionView::Helpers::FormBuilder.send(:include, Effective::FormBuilderInputs)
|
18
10
|
end
|
19
11
|
end
|
20
12
|
|
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.2.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-
|
11
|
+
date: 2015-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -34,21 +34,26 @@ files:
|
|
34
34
|
- MIT-LICENSE
|
35
35
|
- README.md
|
36
36
|
- Rakefile
|
37
|
+
- app/assets/javascripts/effective_date_picker/initialize.js.coffee
|
38
|
+
- app/assets/javascripts/effective_date_picker/input.js
|
37
39
|
- app/assets/javascripts/effective_date_time_picker/bootstrap-datetimepicker.js
|
38
40
|
- app/assets/javascripts/effective_date_time_picker/initialize.js.coffee
|
39
41
|
- app/assets/javascripts/effective_date_time_picker/input.js
|
40
42
|
- app/assets/javascripts/effective_date_time_picker/moment.js
|
41
43
|
- app/assets/javascripts/effective_form_inputs.js
|
44
|
+
- app/assets/stylesheets/effective_date_picker/input.scss
|
42
45
|
- app/assets/stylesheets/effective_date_time_picker/bootstrap-datetimepicker.scss
|
43
46
|
- app/assets/stylesheets/effective_date_time_picker/input.scss
|
44
47
|
- app/assets/stylesheets/effective_form_inputs.scss
|
45
|
-
- app/models/effective/
|
46
|
-
- app/models/
|
47
|
-
- app/models/inputs/
|
48
|
+
- app/models/effective/form_builder_inputs.rb
|
49
|
+
- app/models/effective/form_input.rb
|
50
|
+
- app/models/inputs/effective_date_picker/input.rb
|
51
|
+
- app/models/inputs/effective_date_picker_input.rb
|
52
|
+
- app/models/inputs/effective_date_time_picker/input.rb
|
53
|
+
- app/models/inputs/effective_date_time_picker_input.rb
|
48
54
|
- app/views/effective/style_guide/_form_default.html.haml
|
49
55
|
- lib/effective_form_inputs.rb
|
50
56
|
- lib/effective_form_inputs/engine.rb
|
51
|
-
- lib/effective_form_inputs/form_inputs.rb
|
52
57
|
- lib/effective_form_inputs/version.rb
|
53
58
|
homepage: https://github.com/code-and-effect/effective_form_inputs
|
54
59
|
licenses:
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# In simple_form:
|
2
|
-
#
|
3
|
-
# = f.input :updated_at, :as => :effective_date_time_picker
|
4
|
-
|
5
|
-
if defined?(SimpleForm)
|
6
|
-
|
7
|
-
module EffectiveDateTimePicker
|
8
|
-
class EffectiveDateTimePickerInput < SimpleForm::Inputs::StringInput
|
9
|
-
def input(wrapper_options = nil)
|
10
|
-
options = merge_wrapper_options(input_html_options, wrapper_options) || {}
|
11
|
-
options['data-input-js-options'] = input_options.reject { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) }
|
12
|
-
|
13
|
-
Inputs::EffectiveDateTimePicker::Field.new(object, object_name, template, attribute_name, options).to_html
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|