effective_form_inputs 1.0.1 → 1.0.2
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7900d6d68d9ad85c83f13437bf38defa3ab74a5
|
4
|
+
data.tar.gz: 1a420193c6931459879b81257cab65dc7f46725e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb6e75dbcd8068f41950bbd0c37de005860470d4a7e29d2e6266424b68641280ed3aad58374faba20a418558ea5301e5ed0dea17161a6da114895e662e595034
|
7
|
+
data.tar.gz: ab2d3f112626f0f2a721762b150a620140d95a8a0ad3d415dea61b97d303c9914c23ce10ebfce1957d3ba39a1c841011c8fd993a36628f74707db2bdddfe08dd
|
data/README.md
CHANGED
@@ -691,7 +691,9 @@ To install this form input individually, add the following to your application.c
|
|
691
691
|
|
692
692
|
There is no javascript.
|
693
693
|
|
694
|
-
###
|
694
|
+
### Bootstrap button group
|
695
|
+
|
696
|
+
Pass `buttons: true` to the input options to render as a bootstrap button group.
|
695
697
|
|
696
698
|
As a SimpleForm input:
|
697
699
|
|
@@ -700,13 +702,20 @@ As a SimpleForm input:
|
|
700
702
|
= f.input :breakfast,
|
701
703
|
:as => :effective_radio_buttons,
|
702
704
|
:collection => ['eggs', 'toast', 'bacon'],
|
703
|
-
:
|
705
|
+
:buttons => true
|
704
706
|
```
|
705
707
|
|
706
|
-
###
|
708
|
+
### Images
|
707
709
|
|
708
|
-
|
710
|
+
Pass `images: []` as an array of strings with the same length as the collection to render image buttons.
|
709
711
|
|
712
|
+
```ruby
|
713
|
+
= simple_form_for @user do |f|
|
714
|
+
= f.input :breakfast,
|
715
|
+
:as => :effective_radio_buttons,
|
716
|
+
:collection => ['eggs', 'toast', 'bacon'],
|
717
|
+
:images => [asset_path('eggs.png'), asset_path('toast.png'), asset_path('bacon.png')]
|
718
|
+
```
|
710
719
|
|
711
720
|
## License
|
712
721
|
|
@@ -19,18 +19,22 @@ module Inputs
|
|
19
19
|
|
20
20
|
def to_html
|
21
21
|
initialize_and_validate_images!
|
22
|
-
collection_radio_buttons(@object_name, @method, collection, options[:value_method], options[:label_method],
|
22
|
+
collection_radio_buttons(@object_name, @method, collection, options[:value_method], options[:label_method], options.slice(:checked), item_html_options, &proc { |builder| render_item(builder) })
|
23
23
|
end
|
24
24
|
|
25
25
|
def render_item(builder)
|
26
|
-
if options[:nested_boolean_style] == :nested
|
26
|
+
if options[:nested_boolean_style] == :nested || options[:buttons]
|
27
27
|
item = builder.label { builder.radio_button + item_image_or_text(builder) }
|
28
28
|
else
|
29
29
|
item = builder.radio_button + builder.label { item_image_or_text(builder) }
|
30
30
|
end
|
31
31
|
|
32
32
|
if options[:item_wrapper_tag]
|
33
|
-
|
33
|
+
active = (builder.object.send(options[:value_method]).to_s == value.to_s)
|
34
|
+
|
35
|
+
content_tag(options[:item_wrapper_tag], item,
|
36
|
+
class: ['btn', 'btn-default', options[:item_wrapper_class], ('active' if active)].flatten.uniq.join(' ')
|
37
|
+
)
|
34
38
|
else
|
35
39
|
item
|
36
40
|
end
|
@@ -63,6 +67,10 @@ module Inputs
|
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
70
|
+
def value
|
71
|
+
options[:checked] || super
|
72
|
+
end
|
73
|
+
|
66
74
|
private
|
67
75
|
|
68
76
|
def initialize_and_validate_images!
|
@@ -15,6 +15,10 @@ if defined?(SimpleForm)
|
|
15
15
|
if options[:images]
|
16
16
|
options[:wrapper_html] ||= {}
|
17
17
|
options[:wrapper_html][:class] = "#{options[:wrapper_html][:class]} image_radio_buttons".strip
|
18
|
+
elsif options[:buttons]
|
19
|
+
options[:wrapper_html] ||= {}
|
20
|
+
options[:wrapper_html][:class] = "#{options[:wrapper_html][:class]} button_radio_buttons btn-group".strip
|
21
|
+
options[:wrapper_html][:data] = { toggle: 'buttons' }
|
18
22
|
end
|
19
23
|
|
20
24
|
Inputs::EffectiveRadioButtons::Input.new(object, object_name, template, attribute_name, input_options, (merge_wrapper_options(input_html_options, wrapper_options) || {})).to_html
|
@@ -11,7 +11,7 @@ module Inputs
|
|
11
11
|
if value.kind_of?(String) && value.start_with?('<p>') && value.end_with?('</p>')
|
12
12
|
content_tag(:p, value[3...-4].html_safe, tag_options)
|
13
13
|
else
|
14
|
-
content_tag(:p, (value.html_safe? ? value : value.to_s.html_safe), tag_options)
|
14
|
+
content_tag(:p, (value.html_safe? ? value : (value.to_s || '').html_safe), tag_options)
|
15
15
|
end
|
16
16
|
|
17
17
|
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: 1.0.
|
4
|
+
version: 1.0.2
|
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: 2017-
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|