rails_bootstrap_form 0.5.3 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +111 -2
- data/Gemfile.lock +9 -3
- data/README.md +68 -0
- data/Rakefile +2 -0
- data/app/assets/stylesheets/rails_bootstrap_form.css +3 -0
- data/demo/app/views/users/_form.html.erb +2 -0
- data/demo/app/views/users/_horizontal_form.html.erb +32 -0
- data/demo/app/views/users/_vertical_form.html.erb +8 -8
- data/demo/config/database.yml +7 -15
- data/demo/db/schema.rb +8 -5
- data/gemfiles/common.gemfile +10 -2
- data/lib/rails_bootstrap_form/bootstrap_form_builder.rb +1 -1
- data/lib/rails_bootstrap_form/bootstrap_form_options.rb +21 -3
- data/lib/rails_bootstrap_form/field_wrapper_builder.rb +31 -17
- data/lib/rails_bootstrap_form/{components → helpers}/check_box.rb +10 -3
- data/lib/rails_bootstrap_form/{components → helpers}/errors.rb +1 -1
- data/lib/rails_bootstrap_form/{components → helpers}/help_text.rb +1 -1
- data/lib/rails_bootstrap_form/{components → helpers}/labels.rb +8 -2
- data/lib/rails_bootstrap_form/{components → helpers}/radio_button.rb +10 -3
- data/lib/rails_bootstrap_form/{components → helpers}/required_field.rb +1 -1
- data/lib/rails_bootstrap_form/helpers.rb +45 -0
- data/lib/rails_bootstrap_form/inputs/base.rb +16 -11
- data/lib/rails_bootstrap_form/inputs/check_box.rb +45 -0
- data/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +41 -0
- data/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb +39 -0
- data/lib/rails_bootstrap_form/inputs/collection_select.rb +21 -0
- data/lib/rails_bootstrap_form/inputs/color_field.rb +21 -0
- data/lib/rails_bootstrap_form/inputs/date_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/date_select.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/datetime_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/datetime_local_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/datetime_select.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/email_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/file_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/grouped_collection_select.rb +21 -0
- data/lib/rails_bootstrap_form/inputs/hidden_field.rb +19 -0
- data/lib/rails_bootstrap_form/inputs/month_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/number_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/password_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/phone_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/radio_button.rb +45 -0
- data/lib/rails_bootstrap_form/inputs/range_field.rb +21 -0
- data/lib/rails_bootstrap_form/inputs/search_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/select.rb +21 -0
- data/lib/rails_bootstrap_form/inputs/static_field.rb +30 -0
- data/lib/rails_bootstrap_form/inputs/telephone_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/text_area.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/text_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/time_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/time_select.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/time_zone_select.rb +21 -0
- data/lib/rails_bootstrap_form/inputs/url_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/week_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs.rb +62 -209
- data/lib/rails_bootstrap_form/version.rb +1 -1
- data/lib/rails_bootstrap_form.rb +3 -2
- metadata +70 -10
- data/lib/rails_bootstrap_form/components.rb +0 -23
@@ -3,7 +3,7 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
module RailsBootstrapForm
|
6
|
-
module
|
6
|
+
module Helpers
|
7
7
|
module RadioButton
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
@@ -58,11 +58,18 @@ module RailsBootstrapForm
|
|
58
58
|
def radio_button_wrapper_class(bootstrap_options)
|
59
59
|
classes = Array("form-check")
|
60
60
|
classes << "form-check-inline" if bootstrap_options.inline?
|
61
|
-
classes << "mb-3"
|
61
|
+
classes << "mb-3" unless (bootstrap_options.layout_horizontal? || bootstrap_options.inline?)
|
62
62
|
classes.flatten.compact
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
def radio_button_container_classes(bootstrap_options)
|
66
|
+
classes = Array(bootstrap_options.field_col_wrapper_class)
|
67
|
+
classes << field_offset_class(bootstrap_options.label_col_wrapper_class)
|
68
|
+
classes.flatten.compact
|
69
|
+
end
|
70
|
+
|
71
|
+
private :radio_button_label, :radio_button_classes, :radio_button_label_class,
|
72
|
+
:radio_button_wrapper_class, :radio_button_container_classes
|
66
73
|
end
|
67
74
|
end
|
68
75
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Helpers
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
extend ActiveSupport::Autoload
|
9
|
+
|
10
|
+
autoload :HelpText
|
11
|
+
autoload :Labels
|
12
|
+
autoload :RequiredField
|
13
|
+
autoload :Errors
|
14
|
+
autoload :CheckBox
|
15
|
+
autoload :RadioButton
|
16
|
+
|
17
|
+
include HelpText
|
18
|
+
include Labels
|
19
|
+
include RequiredField
|
20
|
+
include Errors
|
21
|
+
include CheckBox
|
22
|
+
include RadioButton
|
23
|
+
|
24
|
+
def self.included(base_class)
|
25
|
+
def collection_input_checked?(checked, obj, input_value)
|
26
|
+
checked == input_value || Array(checked).try(:include?, input_value) ||
|
27
|
+
checked == obj || Array(checked).try(:include?, obj)
|
28
|
+
end
|
29
|
+
|
30
|
+
def control_specific_class(field_tag_name)
|
31
|
+
"rails-bootstrap-forms-#{field_tag_name.to_s.tr("_", "-")}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def is_size_valid?(bootstrap_options)
|
35
|
+
bootstrap_options.size && %i(sm lg).include?(bootstrap_options.size)
|
36
|
+
end
|
37
|
+
|
38
|
+
def field_offset_class(label_col_wrapper_class)
|
39
|
+
label_col_wrapper_class.gsub(/\bcol-(\w+)-(\d)\b/, 'offset-\1-\2')
|
40
|
+
end
|
41
|
+
|
42
|
+
private :collection_input_checked?, :control_specific_class, :is_size_valid?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -7,21 +7,26 @@ module RailsBootstrapForm
|
|
7
7
|
module Base
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
|
-
|
11
|
-
def
|
12
|
-
|
13
|
-
|
10
|
+
class_methods do
|
11
|
+
def bootstrap_field(field_name)
|
12
|
+
define_method(field_name) do |attribute, options = {}|
|
13
|
+
field_wrapper_builder(attribute, options) do
|
14
|
+
super(attribute, options)
|
15
|
+
end
|
16
|
+
end
|
14
17
|
end
|
15
18
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
+
def bootstrap_select_group(field_name)
|
20
|
+
define_method(field_name) do |attribute, options = {}, html_options = {}|
|
21
|
+
options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
|
19
22
|
|
20
|
-
|
21
|
-
|
23
|
+
field_wrapper_builder(attribute, options, html_options) do
|
24
|
+
tag.div(class: control_specific_class(field_name)) do
|
25
|
+
super(attribute, options, html_options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
22
29
|
end
|
23
|
-
|
24
|
-
private :collection_input_checked?, :control_specific_class, :is_size_valid?
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module CheckBox
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
def check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0", &block)
|
12
|
+
bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap_form))
|
13
|
+
|
14
|
+
options[:class] = check_box_classes(attribute, options)
|
15
|
+
|
16
|
+
check_box_field = super(attribute, options, checked_value, unchecked_value)
|
17
|
+
check_box_help_text = help_text(attribute, bootstrap_options)
|
18
|
+
|
19
|
+
check_box_label = check_box_label(attribute, checked_value, options, bootstrap_options, &block)
|
20
|
+
|
21
|
+
check_box_html = tag.div(**check_box_wrapper_options(bootstrap_options)) do
|
22
|
+
concat(check_box_field)
|
23
|
+
concat(check_box_label)
|
24
|
+
concat(check_box_help_text) unless bootstrap_options.inline?
|
25
|
+
concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?)
|
26
|
+
end
|
27
|
+
|
28
|
+
if bootstrap_options.inline?
|
29
|
+
check_box_html
|
30
|
+
else
|
31
|
+
if bootstrap_options.layout_horizontal?
|
32
|
+
tag.div(class: field_wrapper_classes(bootstrap_options)) do
|
33
|
+
tag.div(class: check_box_container_classes(bootstrap_options)) do
|
34
|
+
check_box_html
|
35
|
+
end
|
36
|
+
end
|
37
|
+
else
|
38
|
+
check_box_html
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module CollectionCheckBoxes
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
def collection_check_boxes(attribute, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
12
|
+
options[:multiple] = true
|
13
|
+
|
14
|
+
inputs = ActiveSupport::SafeBuffer.new
|
15
|
+
|
16
|
+
collection.each do |object|
|
17
|
+
input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
|
18
|
+
input_options = {
|
19
|
+
bootstrap_form: {
|
20
|
+
label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
|
21
|
+
inline: true
|
22
|
+
}
|
23
|
+
}.deep_merge!(options)
|
24
|
+
|
25
|
+
inputs << check_box(attribute, input_options, input_value, nil)
|
26
|
+
end
|
27
|
+
|
28
|
+
if options.delete(:include_hidden) { true }
|
29
|
+
inputs.prepend(hidden_field(attribute, value: "", multiple: options[:multiple]))
|
30
|
+
end
|
31
|
+
|
32
|
+
field_wrapper_builder(attribute, options, html_options) do
|
33
|
+
concat(tag.div(class: control_specific_class(:collection_check_boxes)) do
|
34
|
+
concat(inputs)
|
35
|
+
end)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module CollectionRadioButtons
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
def collection_radio_buttons(attribute, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
12
|
+
inputs = ActiveSupport::SafeBuffer.new
|
13
|
+
|
14
|
+
collection.each do |object|
|
15
|
+
input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
|
16
|
+
input_options = {
|
17
|
+
bootstrap_form: {
|
18
|
+
label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
|
19
|
+
inline: true
|
20
|
+
}
|
21
|
+
}.deep_merge!(options)
|
22
|
+
|
23
|
+
if (checked = input_options[:checked])
|
24
|
+
input_options[:checked] = collection_input_checked?(checked, object, object.send(value_method))
|
25
|
+
end
|
26
|
+
|
27
|
+
inputs << radio_button(attribute, input_value, input_options)
|
28
|
+
end
|
29
|
+
|
30
|
+
field_wrapper_builder(attribute, options, html_options) do
|
31
|
+
concat(tag.div(class: control_specific_class(:collection_radio_buttons)) do
|
32
|
+
concat(inputs)
|
33
|
+
end)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module CollectionSelect
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
def collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {})
|
12
|
+
options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
|
13
|
+
|
14
|
+
field_wrapper_builder(attribute, options, html_options) do
|
15
|
+
super(attribute, collection, value_method, text_method, options, html_options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module ColorField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
def color_field(attribute, options = {})
|
12
|
+
options = {bootstrap_form: {field_class: "form-control form-control-color"}}.deep_merge!(options)
|
13
|
+
|
14
|
+
field_wrapper_builder(attribute, options) do
|
15
|
+
super(attribute, options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module DateField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_field :date_field
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module DateSelect
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_select_group :date_select
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module DatetimeField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_field :datetime_field
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module DatetimeLocalField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_field :datetime_local_field
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module DatetimeSelect
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_select_group :datetime_select
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module EmailField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_field :email_field
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module FileField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_field :file_field
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module GroupedCollectionSelect
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
def grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
|
12
|
+
options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
|
13
|
+
|
14
|
+
field_wrapper_builder(attribute, options, html_options) do
|
15
|
+
super(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module HiddenField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
def hidden_field(attribute, options = {})
|
12
|
+
options[:value] = object.send(attribute) unless options.key?(:value)
|
13
|
+
|
14
|
+
super(attribute, options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module MonthField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_field :month_field
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module NumberField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_field :number_field
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module PasswordField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_field :password_field
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module PhoneField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_field :phone_field
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module RadioButton
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
def radio_button(attribute, value, options = {})
|
12
|
+
bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap_form))
|
13
|
+
|
14
|
+
options[:class] = radio_button_classes(attribute, options)
|
15
|
+
|
16
|
+
radio_button_field = super(attribute, value, options)
|
17
|
+
radio_button_help_text = help_text(attribute, bootstrap_options)
|
18
|
+
|
19
|
+
radio_button_label = radio_button_label(attribute, value, options, bootstrap_options)
|
20
|
+
|
21
|
+
radio_button_html = tag.div(**radio_button_wrapper_options(bootstrap_options)) do
|
22
|
+
concat(radio_button_field)
|
23
|
+
concat(radio_button_label)
|
24
|
+
concat(radio_button_help_text) unless bootstrap_options.inline?
|
25
|
+
concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?)
|
26
|
+
end
|
27
|
+
|
28
|
+
if bootstrap_options.inline?
|
29
|
+
radio_button_html
|
30
|
+
else
|
31
|
+
if bootstrap_options.layout_horizontal?
|
32
|
+
tag.div(class: field_wrapper_classes(bootstrap_options)) do
|
33
|
+
tag.div(class: radio_button_container_classes(bootstrap_options)) do
|
34
|
+
radio_button_html
|
35
|
+
end
|
36
|
+
end
|
37
|
+
else
|
38
|
+
radio_button_html
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module RangeField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
def range_field(attribute, options = {})
|
12
|
+
options = {bootstrap_form: {field_class: "form-range"}}.deep_merge!(options)
|
13
|
+
|
14
|
+
field_wrapper_builder(attribute, options) do
|
15
|
+
super(attribute, options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module SearchField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_field :search_field
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module Select
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
def select(attribute, choices = nil, options = {}, html_options = {}, &block)
|
12
|
+
options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
|
13
|
+
|
14
|
+
field_wrapper_builder(attribute, options, html_options) do
|
15
|
+
super(attribute, choices, options, html_options, &block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module StaticField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
def static_field(*args)
|
12
|
+
options = args.extract_options!
|
13
|
+
attribute = args.first
|
14
|
+
|
15
|
+
static_options = options.merge(
|
16
|
+
readonly: true,
|
17
|
+
disabled: true,
|
18
|
+
bootstrap_form: {
|
19
|
+
field_class: bootstrap_form_options.static_field_class
|
20
|
+
}
|
21
|
+
)
|
22
|
+
|
23
|
+
static_options[:value] = object.send(attribute) unless options.key?(:value)
|
24
|
+
|
25
|
+
text_field(attribute, static_options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
module RailsBootstrapForm
|
6
|
+
module Inputs
|
7
|
+
module TelephoneField
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
bootstrap_field :telephone_field
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|