volt-fields 0.1.3 → 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/.gitignore +1 -0
- data/README.md +37 -9
- data/VERSION +1 -1
- data/app/fields/controllers/button_group_controller.rb +28 -0
- data/app/fields/controllers/main_controller.rb +8 -1
- data/app/fields/controllers/radio_controller.rb +10 -7
- data/app/fields/controllers/select_controller.rb +2 -13
- data/app/fields/controllers/select_radio_controller.rb +16 -0
- data/app/fields/views/button_group/index.html +21 -0
- data/app/fields/views/button_group/justified.html +23 -0
- data/app/fields/views/radio/index.html +18 -18
- data/app/fields/views/radio/inline.html +15 -18
- data/app/fields/views/select/index.html +8 -6
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c9d96aca673395cee2c2ee656eb50fe29c44301
|
4
|
+
data.tar.gz: c8d8b64589e87542026de04cf4b0a6f1e93902c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e63b11644a0d388832d24b48a0309900955a442dbea06f765a81e5563163ec525e2e9529d65e9c50ee607ae93ab5bf2f6c73bbef36896aa444f812d05656af9c
|
7
|
+
data.tar.gz: e9bf741a68f1ba7140c4eb8e30cd12f60f5e71170e48a5b1dd4475fef323d0db8a00cda033bc24fb704f1ce180df1786bbde6e4320d03739b0d5e6ea0303700d
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -12,9 +12,10 @@ Currently supported control types:
|
|
12
12
|
* Select
|
13
13
|
* Radio
|
14
14
|
* Checkbox
|
15
|
+
* Button groups / bar
|
15
16
|
|
16
17
|
## How to Use
|
17
|
-
|
18
|
+
#### Setup
|
18
19
|
Include in your gemfile:
|
19
20
|
|
20
21
|
```
|
@@ -26,20 +27,46 @@ Then use fields as tags in your views:
|
|
26
27
|
<:fields:text value="{{ model.first_name }}"/>
|
27
28
|
```
|
28
29
|
|
29
|
-
|
30
|
+
#### Options common to all controls
|
31
|
+
Attribute | Description | Required/Optional | Default
|
32
|
+
----- | ----- | -----
|
33
|
+
value | The model field to bind to. | Required | None |
|
34
|
+
label | A label for the field. Pass 'false' for no label. | Optional | Name of the field on the model.
|
35
|
+
|
36
|
+
### Control Types
|
37
|
+
|
38
|
+
#### Text and Textarea
|
30
39
|
```
|
31
40
|
<:fields:text value="{{ model.first_name }}"/>
|
32
41
|
```
|
42
|
+
##### Alternative formats
|
43
|
+
* <:fields:textarea />
|
33
44
|
|
34
|
-
|
35
|
-
Select fields accept either an array of options, or an array of {label: '', value: ''} hashes.
|
45
|
+
#### Select
|
46
|
+
Select fields accept either an array of options, or an array of {label: '', value: ''} hashes. You can pass promises and the options will be populated when the promise resolves.
|
36
47
|
|
37
48
|
```
|
38
49
|
<:fields:select value="{{ model.role }}" options="{{ ['User', 'Admin', 'Something Else']}}"/>
|
39
50
|
```
|
40
|
-
|
41
|
-
|
42
|
-
|
51
|
+
|
52
|
+
#### Button Groups / Bar
|
53
|
+
[Button groups](http://getbootstrap.com/components/#btn-groups) function just like select boxes, but provide a switch-like interface.
|
54
|
+
|
55
|
+
```
|
56
|
+
<:fields:button_group selected_button_class="btn-primary" value="{{ model.status }}" options="{{ MyModel.something_that_returns_a_promise }}" />
|
57
|
+
```
|
58
|
+
|
59
|
+
Attribute | Description | Default
|
60
|
+
------ | ------ | -------
|
61
|
+
button_class | Class to apply to all buttons (unless selected_button_class is also supplied) (i.e. btn-default, btn-primary) | 'btn-default'
|
62
|
+
active_class | Class applied to the selected option (in addition to selected_button_class (i.e. 'active') | 'active'
|
63
|
+
selected_button_class | Class to apply to the selected button (i.e. btn-default, btn-primary) | 'btn-default'
|
64
|
+
|
65
|
+
##### Alternative formats
|
66
|
+
* <:fields:button_group:justified />
|
67
|
+
|
68
|
+
#### Radio
|
69
|
+
Radio buttons accept either an array of options, or an array of {label: '', value: ''} hashes.
|
43
70
|
|
44
71
|
```
|
45
72
|
<:fields:radio value="{{ model.active }}" options="{{[{label: 'Active', value: true},{label:'Inactive', value: false}]}}"/>
|
@@ -47,10 +74,11 @@ For radio buttons, pass an options array of {label: '', value: ''} hashes.
|
|
47
74
|
|
48
75
|
For inline radio buttons, use ```:fields:radio:inline```.
|
49
76
|
|
50
|
-
|
77
|
+
#### Checkbox
|
51
78
|
For checkboxes, use 'checked' instead of 'value' to bind the checkbox to a boolean field.
|
52
79
|
```
|
53
80
|
<:fields:checkbox checked="{{ model.active }}"/>
|
54
81
|
```
|
55
82
|
|
56
|
-
|
83
|
+
##### Alternative formats
|
84
|
+
* <:fields:checkbox:inline />
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'fields/controllers/main_controller'
|
2
|
+
require 'fields/controllers/select_radio_controller'
|
3
|
+
|
4
|
+
module Fields
|
5
|
+
class ButtonGroupController < SelectRadioController
|
6
|
+
|
7
|
+
def selected?(value)
|
8
|
+
true if value == model_inst.send(@field_name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_val(value)
|
12
|
+
model_inst.send("#{@field_name}=", value)
|
13
|
+
end
|
14
|
+
|
15
|
+
def button_class
|
16
|
+
attrs.button_class || 'btn-default'
|
17
|
+
end
|
18
|
+
|
19
|
+
def selected_button_class
|
20
|
+
attrs.selected_button_class || attrs.button_class || 'btn-default'
|
21
|
+
end
|
22
|
+
|
23
|
+
def active_class
|
24
|
+
attrs.active_class || 'active'
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Fields
|
2
2
|
class MainController < Volt::ModelController
|
3
3
|
before_action :setup_field
|
4
|
+
reactive_accessor :options
|
4
5
|
|
5
6
|
def setup_field
|
6
7
|
# Default to text fields
|
@@ -26,7 +27,9 @@ module Fields
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def label
|
29
|
-
attrs.label
|
30
|
+
unless ['false','False'].include?(attrs.label)
|
31
|
+
attrs.label || @field_name.titleize
|
32
|
+
end
|
30
33
|
end
|
31
34
|
|
32
35
|
# Find the errors for this field
|
@@ -34,6 +37,10 @@ module Fields
|
|
34
37
|
model_inst.marked_errors[@field_name]
|
35
38
|
end
|
36
39
|
|
40
|
+
def field_name
|
41
|
+
@field_name
|
42
|
+
end
|
43
|
+
|
37
44
|
# When a field goes out of focus, then we want to start checking a field
|
38
45
|
def blur
|
39
46
|
model_inst.mark_field!(@field_name)
|
@@ -1,15 +1,18 @@
|
|
1
1
|
require 'fields/controllers/main_controller'
|
2
|
+
require 'fields/controllers/select_radio_controller'
|
2
3
|
|
3
4
|
module Fields
|
4
|
-
class RadioController <
|
5
|
-
|
6
|
-
|
7
|
-
model_inst.send("#{@field_name}=", value)
|
8
|
-
model_inst.mark_field!(@field_name)
|
5
|
+
class RadioController < SelectRadioController
|
6
|
+
def name
|
7
|
+
attrs.name || "#{field_name}_radio"
|
9
8
|
end
|
10
9
|
|
11
|
-
def
|
12
|
-
value == model_inst.send(@field_name)
|
10
|
+
def selected?(option)
|
11
|
+
option[:value] == model_inst.send(@field_name) ? true : false
|
12
|
+
end
|
13
|
+
|
14
|
+
def set(option)
|
15
|
+
model_inst.send("#{@field_name}=", option[:value])
|
13
16
|
end
|
14
17
|
end
|
15
18
|
end
|
@@ -1,18 +1,7 @@
|
|
1
1
|
require 'fields/controllers/main_controller'
|
2
|
+
require 'fields/controllers/select_radio_controller'
|
2
3
|
|
3
4
|
module Fields
|
4
|
-
class SelectController <
|
5
|
-
def options
|
6
|
-
if attrs.options[0].is_a?(Hash)
|
7
|
-
options = attrs.options
|
8
|
-
else
|
9
|
-
options = attrs.options.collect { |option| { value: option, label: option } }
|
10
|
-
end
|
11
|
-
options
|
12
|
-
end
|
13
|
-
|
14
|
-
def selected?(value)
|
15
|
-
true if value == model_inst.send(@field_name)
|
16
|
-
end
|
5
|
+
class SelectController < SelectRadioController
|
17
6
|
end
|
18
7
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fields/controllers/main_controller'
|
2
|
+
|
3
|
+
module Fields
|
4
|
+
class SelectRadioController < MainController
|
5
|
+
def options
|
6
|
+
attrs.options.then do |options|
|
7
|
+
if options[0].is_a?(Hash)
|
8
|
+
options_hash = options
|
9
|
+
else
|
10
|
+
options_hash = options.collect { |option| {value: option, label: option }}
|
11
|
+
end
|
12
|
+
options_hash
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<:Body>
|
2
|
+
<div class="form-group {{ if errors }}has-error{{ elsif marked }}has-success{{ end }} has-feedback">
|
3
|
+
{{ if label }}
|
4
|
+
<label class="control-label">{{ label }}</label>
|
5
|
+
{{ end }}
|
6
|
+
<div class="btn-group" role="group">
|
7
|
+
{{ options.each do |option| }}
|
8
|
+
{{ if selected?(option[:value]) }}
|
9
|
+
<button type="button" class="btn {{ selected_button_class }} {{ active_class }}" e-click="set_val(option[:value])"> {{ option[:label] }}</option>
|
10
|
+
{{ else }}
|
11
|
+
<button type="button" class="btn {{ button_class }}" e-click="set_val(option[:value])"> {{ option[:label] }}</option>
|
12
|
+
{{ end }}
|
13
|
+
{{ end }}
|
14
|
+
</div>
|
15
|
+
{{ if errors }}
|
16
|
+
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
|
17
|
+
<span class="control-label errors">{{ (errors || []).join(', ') }}</span>
|
18
|
+
{{ elsif marked }}
|
19
|
+
<span class="glyphicon glyphicon-ok form-control-feedback"></span>
|
20
|
+
{{ end }}
|
21
|
+
</div>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<:Body>
|
2
|
+
<div class="form-group {{ if errors }}has-error{{ elsif marked }}has-success{{ end }} has-feedback">
|
3
|
+
{{ if label }}
|
4
|
+
<label class="control-label">{{ label }}</label>
|
5
|
+
{{ end }}
|
6
|
+
<div class="btn-group btn-group-justified" role="group">
|
7
|
+
<div class="btn-group" role="group">
|
8
|
+
{{ options.each do |option| }}
|
9
|
+
{{ if selected?(option[:value]) }}
|
10
|
+
<button type="button" class="btn {{ selected_button_class }} {{ active_class }}" e-click="set_val(option[:value])"> {{ option[:label] }}</option>
|
11
|
+
{{ else }}
|
12
|
+
<button type="button" class="btn {{ button_class }}" e-click="set_val(option[:value])"> {{ option[:label] }}</option>
|
13
|
+
{{ end }}
|
14
|
+
{{ end }}
|
15
|
+
</div>
|
16
|
+
</div>
|
17
|
+
{{ if errors }}
|
18
|
+
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
|
19
|
+
<span class="control-label errors">{{ (errors || []).join(', ') }}</span>
|
20
|
+
{{ elsif marked }}
|
21
|
+
<span class="glyphicon glyphicon-ok form-control-feedback"></span>
|
22
|
+
{{ end }}
|
23
|
+
</div>
|
@@ -1,24 +1,24 @@
|
|
1
1
|
<:Body>
|
2
2
|
<div class="{{ if errors }}has-error{{ elsif marked }}has-success{{ end }} has-feedback">
|
3
|
-
{{
|
3
|
+
{{ if label }}
|
4
|
+
<label class="control-label">{{ label }}</label>
|
5
|
+
{{ end }}
|
6
|
+
{{ options.each do |option| }}
|
4
7
|
<div class="radio">
|
5
|
-
|
6
|
-
|
7
|
-
<input type="radio" e-click="
|
8
|
-
|
9
|
-
|
10
|
-
{{ if errors }}
|
11
|
-
<span class="glyphicon glyphicon-remove"></span>
|
12
|
-
<span class="control-label errors">{{ (errors || []).join(', ') }}</span>
|
13
|
-
{{ elsif marked }}
|
14
|
-
<span class="glyphicon glyphicon-ok"></span>
|
8
|
+
<label>
|
9
|
+
{{ if selected?(option) }}
|
10
|
+
<input type="radio" e-click="set(option)" name="{{ name }}" value="{{ option[:value] }}" checked/>
|
11
|
+
{{ else }}
|
12
|
+
<input type="radio" e-click="set(option)" name="{{ name }}" value="{{ option[:value] }}"/>
|
15
13
|
{{ end }}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
{{ option[:label] }}
|
15
|
+
</label>
|
16
|
+
{{ if errors }}
|
17
|
+
<span class="glyphicon glyphicon-remove"></span>
|
18
|
+
<span class="control-label errors">{{ (errors || []).join(', ') }}</span>
|
19
|
+
{{ elsif marked }}
|
20
|
+
<span class="glyphicon glyphicon-ok"></span>
|
21
21
|
{{ end }}
|
22
|
+
</div>
|
22
23
|
{{ end }}
|
23
|
-
|
24
|
-
</div>
|
24
|
+
</div>
|
@@ -1,24 +1,21 @@
|
|
1
1
|
<:Body>
|
2
2
|
<div class="{{ if errors }}has-error{{ elsif marked }}has-success{{ end }} has-feedback">
|
3
|
-
{{
|
3
|
+
{{ options.each do |option| }}
|
4
4
|
<div class="radio-inline">
|
5
|
-
|
6
|
-
|
7
|
-
<input type="radio" e-click="
|
8
|
-
|
9
|
-
|
10
|
-
{{ if errors }}
|
11
|
-
<span class="glyphicon glyphicon-remove"></span>
|
12
|
-
<span class="control-label errors">{{ (errors || []).join(', ') }}</span>
|
13
|
-
{{ elsif marked }}
|
14
|
-
<span class="glyphicon glyphicon-ok"></span>
|
5
|
+
<label>
|
6
|
+
{{ if selected?(option) }}
|
7
|
+
<input type="radio" e-click="set(option)" name="{{ name }}" value="{{ option[:value] }}" checked/>
|
8
|
+
{{ else }}
|
9
|
+
<input type="radio" e-click="set(option)" name="{{ name }}" value="{{ option[:value] }}"/>
|
15
10
|
{{ end }}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
{{ option[:label] }}
|
12
|
+
</label>
|
13
|
+
{{ if errors }}
|
14
|
+
<span class="glyphicon glyphicon-remove"></span>
|
15
|
+
<span class="control-label errors">{{ (errors || []).join(', ') }}</span>
|
16
|
+
{{ elsif marked }}
|
17
|
+
<span class="glyphicon glyphicon-ok"></span>
|
21
18
|
{{ end }}
|
19
|
+
</div>
|
22
20
|
{{ end }}
|
23
|
-
|
24
|
-
</div>
|
21
|
+
</div>
|
@@ -3,13 +3,15 @@
|
|
3
3
|
{{ if label }}
|
4
4
|
<label class="control-label">{{ label }}</label>
|
5
5
|
{{ end }}
|
6
|
-
<select value="{{ attrs.value }}" e-
|
6
|
+
<select value="{{ attrs.value }}" e-change="blur" class="form-control">
|
7
|
+
{{ if attrs.value.nil? }}
|
8
|
+
<option value="" selected>
|
9
|
+
</option>
|
10
|
+
{{ end }}
|
7
11
|
{{ options.each do |option| }}
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
<option value="{{ option[:value] }}"> {{ option[:label] }}</option>
|
12
|
-
{{ end }}
|
12
|
+
<option value="{{ option[:value] }}">
|
13
|
+
{{ option[:label] }}
|
14
|
+
</option>
|
13
15
|
{{ end }}
|
14
16
|
</select>
|
15
17
|
{{ if errors }}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: volt-fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Stout
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,12 +38,16 @@ files:
|
|
38
38
|
- VERSION
|
39
39
|
- app/fields/config/dependencies.rb
|
40
40
|
- app/fields/config/routes.rb
|
41
|
+
- app/fields/controllers/button_group_controller.rb
|
41
42
|
- app/fields/controllers/checkbox_controller.rb
|
42
43
|
- app/fields/controllers/main_controller.rb
|
43
44
|
- app/fields/controllers/radio_controller.rb
|
44
45
|
- app/fields/controllers/select_controller.rb
|
46
|
+
- app/fields/controllers/select_radio_controller.rb
|
45
47
|
- app/fields/controllers/text_controller.rb
|
46
48
|
- app/fields/controllers/textarea_controller.rb
|
49
|
+
- app/fields/views/button_group/index.html
|
50
|
+
- app/fields/views/button_group/justified.html
|
47
51
|
- app/fields/views/checkbox/index.html
|
48
52
|
- app/fields/views/checkbox/inline.html
|
49
53
|
- app/fields/views/radio/index.html
|