simple_form-bootstrap 1.1.0 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +12 -12
- data/app/assets/javascripts/simple_form-bootstrap.js +24 -24
- data/app/assets/javascripts/simple_form-bootstrap/date_time_input.js +1 -0
- data/app/assets/javascripts/simple_form-bootstrap/select_input.js +12 -12
- data/lib/simple_form/bootstrap.rb +26 -26
- data/lib/simple_form/bootstrap/engine.rb +2 -2
- data/lib/simple_form/bootstrap/form_builders.rb +9 -9
- data/lib/simple_form/bootstrap/form_builders/button.rb +26 -23
- data/lib/simple_form/bootstrap/form_builders/date_time.rb +26 -26
- data/lib/simple_form/bootstrap/inputs.rb +7 -7
- data/lib/simple_form/bootstrap/inputs/date_time_input.rb +13 -12
- data/lib/simple_form/bootstrap/railtie.rb +5 -5
- data/lib/simple_form/bootstrap/setup.rb +189 -189
- data/lib/simple_form/bootstrap/version.rb +4 -4
- 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: d6ea0957545a4c17950bdf09f9237b1b9d65aa21
|
4
|
+
data.tar.gz: db3a33a12b1795eabd4815608cb34fab6a8e6ed5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4cecfc6d0e988e6887a37f92bf69ded8cd6684745037394b26c684b7496c06c933e9403d953a3e46325f326fa7d860b68a90bbbed5328d7b04cb2b6b74c17c1
|
7
|
+
data.tar.gz: db340e776a16319c2a82c7fd824b9daf20fd3c98d13ac4189cb24fe8d711f33df0acbef15bcdab878c3a98601de3b37aa1ff9117a526574f57aab27af4bf9c42
|
data/Rakefile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
begin
|
2
|
-
require 'bundler/setup'
|
3
|
-
rescue LoadError
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
-
end
|
6
|
-
|
7
|
-
require "rspec/core/rake_task"
|
8
|
-
|
9
|
-
RSpec::Core::RakeTask.new
|
10
|
-
|
11
|
-
task :default => :spec
|
12
|
-
task :test => :spec
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require "rspec/core/rake_task"
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new
|
10
|
+
|
11
|
+
task :default => :spec
|
12
|
+
task :test => :spec
|
@@ -1,24 +1,24 @@
|
|
1
|
-
//= require simple_form-bootstrap/date_time_input
|
2
|
-
|
3
|
-
(function($) {
|
4
|
-
'use strict';
|
5
|
-
function initializeComponents(node) {
|
6
|
-
// Enable our date/time pickers
|
7
|
-
var datePickers = $('input.bootstrap-datepicker', node);
|
8
|
-
datePickers.datetimepicker();
|
9
|
-
|
10
|
-
// Enable our styled Bootstrap select controls, except Twitter Typeahead controls.
|
11
|
-
var selects = $('select.form-control:not(.typeahead)', node);
|
12
|
-
selects.selectpicker();
|
13
|
-
}
|
14
|
-
|
15
|
-
$(document).on('ready', function(e) {
|
16
|
-
initializeComponents(document);
|
17
|
-
});
|
18
|
-
$(document).on('DOMNodeInserted', function(e) {
|
19
|
-
initializeComponents(e.target);
|
20
|
-
});
|
21
|
-
$(document).on('nested:fieldAdded', function(e) {
|
22
|
-
initializeComponents(e.field);
|
23
|
-
});
|
24
|
-
})(jQuery);
|
1
|
+
//= require simple_form-bootstrap/date_time_input
|
2
|
+
|
3
|
+
(function($) {
|
4
|
+
'use strict';
|
5
|
+
function initializeComponents(node) {
|
6
|
+
// Enable our date/time pickers
|
7
|
+
var datePickers = $('input.bootstrap-datepicker', node);
|
8
|
+
datePickers.datetimepicker();
|
9
|
+
|
10
|
+
// Enable our styled Bootstrap select controls, except Twitter Typeahead controls.
|
11
|
+
var selects = $('select.form-control:not(.typeahead)', node);
|
12
|
+
selects.selectpicker();
|
13
|
+
}
|
14
|
+
|
15
|
+
$(document).on('ready', function(e) {
|
16
|
+
initializeComponents(document);
|
17
|
+
});
|
18
|
+
$(document).on('DOMNodeInserted', function(e) {
|
19
|
+
initializeComponents(e.target);
|
20
|
+
});
|
21
|
+
$(document).on('nested:fieldAdded', function(e) {
|
22
|
+
initializeComponents(e.field);
|
23
|
+
});
|
24
|
+
})(jQuery);
|
@@ -1,12 +1,12 @@
|
|
1
|
-
// Hijacks the default Bootstrap date-time picker to always format dates in the specified format
|
2
|
-
// through the use of a hidden field.
|
3
|
-
(function($) {
|
4
|
-
'use strict';
|
5
|
-
if ($.fn.selectpicker) {
|
6
|
-
return;
|
7
|
-
}
|
8
|
-
|
9
|
-
$.fn.selectpicker = function(arg) {
|
10
|
-
return methods.initialise.call(this, arg);
|
11
|
-
};
|
12
|
-
}(jQuery));
|
1
|
+
// Hijacks the default Bootstrap date-time picker to always format dates in the specified format
|
2
|
+
// through the use of a hidden field.
|
3
|
+
(function($) {
|
4
|
+
'use strict';
|
5
|
+
if ($.fn.selectpicker) {
|
6
|
+
return;
|
7
|
+
}
|
8
|
+
|
9
|
+
$.fn.selectpicker = function(arg) {
|
10
|
+
return methods.initialise.call(this, arg);
|
11
|
+
};
|
12
|
+
}(jQuery));
|
@@ -1,26 +1,26 @@
|
|
1
|
-
module SimpleForm::Bootstrap
|
2
|
-
extend ActiveSupport::Autoload
|
3
|
-
|
4
|
-
autoload :Setup
|
5
|
-
autoload :FormBuilders
|
6
|
-
|
7
|
-
eager_autoload do
|
8
|
-
autoload :Inputs
|
9
|
-
end
|
10
|
-
|
11
|
-
# Because we are augmenting Simple Form with our input fields, we need to load even when eager
|
12
|
-
# loading is not enabled
|
13
|
-
SimpleForm::Bootstrap::FormBuilders.load!
|
14
|
-
end
|
15
|
-
|
16
|
-
module SimpleForm
|
17
|
-
class << self
|
18
|
-
# Extend the normal Simple Form configuration options with ours.
|
19
|
-
prepend SimpleForm::Bootstrap::Setup
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
if defined?(Rails)
|
24
|
-
require 'simple_form/bootstrap/railtie'
|
25
|
-
require 'simple_form/bootstrap/engine'
|
26
|
-
end
|
1
|
+
module SimpleForm::Bootstrap
|
2
|
+
extend ActiveSupport::Autoload
|
3
|
+
|
4
|
+
autoload :Setup
|
5
|
+
autoload :FormBuilders
|
6
|
+
|
7
|
+
eager_autoload do
|
8
|
+
autoload :Inputs
|
9
|
+
end
|
10
|
+
|
11
|
+
# Because we are augmenting Simple Form with our input fields, we need to load even when eager
|
12
|
+
# loading is not enabled
|
13
|
+
SimpleForm::Bootstrap::FormBuilders.load!
|
14
|
+
end
|
15
|
+
|
16
|
+
module SimpleForm
|
17
|
+
class << self
|
18
|
+
# Extend the normal Simple Form configuration options with ours.
|
19
|
+
prepend SimpleForm::Bootstrap::Setup
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if defined?(Rails)
|
24
|
+
require 'simple_form/bootstrap/railtie'
|
25
|
+
require 'simple_form/bootstrap/engine'
|
26
|
+
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class SimpleForm::Bootstrap::Engine < Rails::Engine
|
2
|
-
end
|
1
|
+
class SimpleForm::Bootstrap::Engine < Rails::Engine
|
2
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module SimpleForm::Bootstrap::FormBuilders
|
2
|
-
extend ActiveSupport::Autoload
|
3
|
-
|
4
|
-
def self.load!
|
5
|
-
Dir.glob("#{__dir__}/form_builders/*") do |path|
|
6
|
-
require path
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
1
|
+
module SimpleForm::Bootstrap::FormBuilders
|
2
|
+
extend ActiveSupport::Autoload
|
3
|
+
|
4
|
+
def self.load!
|
5
|
+
Dir.glob("#{__dir__}/form_builders/*") do |path|
|
6
|
+
require path
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -1,23 +1,26 @@
|
|
1
|
-
module SimpleForm::Bootstrap::FormBuilders::Button
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
1
|
+
module SimpleForm::Bootstrap::FormBuilders::Button
|
2
|
+
BUTTON_CLASSES = ['btn-default', 'btn-primary', 'btn-success', 'btn-info', 'btn-warning',
|
3
|
+
'btn-danger', 'btn-link'].freeze
|
4
|
+
|
5
|
+
# Adds the btn-default class selectively to buttons which do not have an explicit button type.
|
6
|
+
def button(type, *args, &proc)
|
7
|
+
options = args.extract_options!.dup
|
8
|
+
options[:class] = [*options[:class]]
|
9
|
+
|
10
|
+
# Add the specified class type.
|
11
|
+
if options[:class].select { |cls| BUTTON_CLASSES.include?(cls) }.empty?
|
12
|
+
if type.to_s == :submit.to_s.freeze
|
13
|
+
options[:class] << 'btn-primary'
|
14
|
+
else
|
15
|
+
options[:class] << 'btn-default'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
args << options
|
19
|
+
|
20
|
+
super(type, *args, &proc)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
SimpleForm::FormBuilder.class_eval do
|
25
|
+
prepend SimpleForm::Bootstrap::FormBuilders::Button
|
26
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
module SimpleForm::Bootstrap::FormBuilders::DateTime
|
2
|
-
DATE_TIME_COLUMN_TYPES = [
|
3
|
-
'datetime',
|
4
|
-
'timestamp',
|
5
|
-
'timestamp without time zone'
|
6
|
-
].freeze
|
7
|
-
|
8
|
-
DATE_COLUMN_TYPES = [
|
9
|
-
'date'
|
10
|
-
].freeze
|
11
|
-
|
12
|
-
def default_input_type(attribute_name, column, options, *args, &block)
|
13
|
-
if (options.is_a?(Hash) ? options[:as] : @options[:as]).nil? && !column.nil?
|
14
|
-
return :bootstrap_date_time if DATE_TIME_COLUMN_TYPES.include?(column.sql_type)
|
15
|
-
return :bootstrap_date if DATE_COLUMN_TYPES.include?(column.sql_type)
|
16
|
-
end
|
17
|
-
|
18
|
-
super(attribute_name, column, options, *args, &block)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
SimpleForm::FormBuilder.class_eval do
|
23
|
-
prepend SimpleForm::Bootstrap::FormBuilders::DateTime
|
24
|
-
|
25
|
-
map_type :bootstrap_date_time, :bootstrap_date, to: SimpleForm::Bootstrap::Inputs::DateTimeInput
|
26
|
-
end
|
1
|
+
module SimpleForm::Bootstrap::FormBuilders::DateTime
|
2
|
+
DATE_TIME_COLUMN_TYPES = [
|
3
|
+
'datetime',
|
4
|
+
'timestamp',
|
5
|
+
'timestamp without time zone'
|
6
|
+
].freeze
|
7
|
+
|
8
|
+
DATE_COLUMN_TYPES = [
|
9
|
+
'date'
|
10
|
+
].freeze
|
11
|
+
|
12
|
+
def default_input_type(attribute_name, column, options, *args, &block)
|
13
|
+
if (options.is_a?(Hash) ? options[:as] : @options[:as]).nil? && !column.nil?
|
14
|
+
return :bootstrap_date_time if DATE_TIME_COLUMN_TYPES.include?(column.sql_type)
|
15
|
+
return :bootstrap_date if DATE_COLUMN_TYPES.include?(column.sql_type)
|
16
|
+
end
|
17
|
+
|
18
|
+
super(attribute_name, column, options, *args, &block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
SimpleForm::FormBuilder.class_eval do
|
23
|
+
prepend SimpleForm::Bootstrap::FormBuilders::DateTime
|
24
|
+
|
25
|
+
map_type :bootstrap_date_time, :bootstrap_date, to: SimpleForm::Bootstrap::Inputs::DateTimeInput
|
26
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
module SimpleForm::Bootstrap::Inputs
|
2
|
-
extend ActiveSupport::Autoload
|
3
|
-
|
4
|
-
eager_autoload do
|
5
|
-
autoload :DateTimeInput
|
6
|
-
end
|
7
|
-
end
|
1
|
+
module SimpleForm::Bootstrap::Inputs
|
2
|
+
extend ActiveSupport::Autoload
|
3
|
+
|
4
|
+
eager_autoload do
|
5
|
+
autoload :DateTimeInput
|
6
|
+
end
|
7
|
+
end
|
@@ -9,24 +9,25 @@ class SimpleForm::Bootstrap::Inputs::DateTimeInput < SimpleForm::Inputs::Base
|
|
9
9
|
# Integrate with Bootstrap's styling
|
10
10
|
text_field_options[:class] << 'form-control'
|
11
11
|
|
12
|
-
hidden_field_options = text_field_options.
|
13
|
-
hidden_field_options[:class]
|
12
|
+
hidden_field_options = text_field_options.deep_dup
|
13
|
+
hidden_field_options[:class] << 'bootstrap-datepicker'
|
14
|
+
hidden_field_options[:class] << 'bootstrap-timepicker' if input_type == :bootstrap_date_time
|
14
15
|
hidden_field_options[:id] = "#{attribute_name}_hidden"
|
15
|
-
hidden_field_options[:value] ||= value(object)
|
16
|
-
|
17
|
-
text_field_options[:class] << 'bootstrap-timepicker' if input_type == :bootstrap_date_time
|
18
|
-
text_field_options[:value] ||= format_date(value(object), format)
|
19
|
-
text_field_options[:data] = { 'date-format' => strftime_to_momentjs_format(format) }
|
16
|
+
hidden_field_options[:value] ||= format_date(value(object), format)
|
17
|
+
hidden_field_options[:data] = { 'date-format' => strftime_to_momentjs_format(format) }
|
20
18
|
|
21
|
-
|
22
|
-
|
19
|
+
hidden_field_group_classes = hidden_field_options[:class].dup
|
20
|
+
hidden_field_group_classes.delete('form-control')
|
21
|
+
|
22
|
+
|
23
|
+
text_field_options[:value] ||= value(object).try(:to_s)
|
23
24
|
|
24
25
|
return_string = <<-END_INPUT
|
25
|
-
<div class="input-group #{
|
26
|
-
#{@builder.hidden_field(attribute_name,
|
26
|
+
<div class="input-group #{hidden_field_group_classes.join(' ')}" style="display: none">
|
27
|
+
#{@builder.hidden_field(attribute_name, hidden_field_options.to_hash)}
|
27
28
|
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
|
28
29
|
</div>
|
29
|
-
#{@builder.text_field(attribute_name,
|
30
|
+
#{@builder.text_field(attribute_name, text_field_options.to_hash)}
|
30
31
|
END_INPUT
|
31
32
|
return_string.html_safe
|
32
33
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'rails/railtie'
|
2
|
-
|
3
|
-
class SimpleForm::Bootstrap::Railtie < Rails::Railtie
|
4
|
-
config.eager_load_namespaces << SimpleForm::Bootstrap
|
5
|
-
end
|
1
|
+
require 'rails/railtie'
|
2
|
+
|
3
|
+
class SimpleForm::Bootstrap::Railtie < Rails::Railtie
|
4
|
+
config.eager_load_namespaces << SimpleForm::Bootstrap
|
5
|
+
end
|
@@ -1,189 +1,189 @@
|
|
1
|
-
# Handles configuration Simple Form with Bootstrap defaults.
|
2
|
-
module SimpleForm::Bootstrap::Setup
|
3
|
-
def setup
|
4
|
-
super do |config|
|
5
|
-
yield config
|
6
|
-
configure_simple_form(config)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def configure_simple_form(config)
|
13
|
-
config.error_notification_tag = :div
|
14
|
-
config.error_notification_class = 'alert alert-danger'
|
15
|
-
config.button_class = 'btn'
|
16
|
-
config.boolean_style = :nested
|
17
|
-
config.boolean_label_class = nil
|
18
|
-
|
19
|
-
configure_wrappers(config)
|
20
|
-
|
21
|
-
# Wrappers for forms and inputs using the Bootstrap toolkit.
|
22
|
-
# Check the Bootstrap docs (http://getbootstrap.com)
|
23
|
-
# to learn about the different styles for forms and inputs,
|
24
|
-
# buttons and other elements.
|
25
|
-
config.default_wrapper = :vertical_form
|
26
|
-
config.wrapper_mappings = {
|
27
|
-
check_boxes: :vertical_radio_and_checkboxes,
|
28
|
-
radio_buttons: :vertical_radio_and_checkboxes,
|
29
|
-
file: :vertical_file_input,
|
30
|
-
boolean: :vertical_boolean,
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
def configure_wrappers(config)
|
35
|
-
configure_vertical_form_wrapper(config)
|
36
|
-
configure_vertical_file_input_wrapper(config)
|
37
|
-
configure_vertical_boolean_wrapper(config)
|
38
|
-
configure_vertical_radio_and_checkboxes_wrapper(config)
|
39
|
-
configure_horizontal_form_wrapper(config)
|
40
|
-
configure_horizontal_file_input_wrapper(config)
|
41
|
-
configure_horizontal_boolean_wrapper(config)
|
42
|
-
configure_horizontal_radio_and_checkboxes_wrapper(config)
|
43
|
-
configure_inline_form_wrapper(config)
|
44
|
-
end
|
45
|
-
|
46
|
-
def configure_vertical_form_wrapper(config)
|
47
|
-
config.wrappers :vertical_form, tag: 'div', class: 'form-group',
|
48
|
-
error_class: 'has-error' do |b|
|
49
|
-
b.use :html5
|
50
|
-
b.use :placeholder
|
51
|
-
b.optional :maxlength
|
52
|
-
b.optional :pattern
|
53
|
-
b.optional :min_max
|
54
|
-
b.optional :readonly
|
55
|
-
b.use :label, class: 'control-label'
|
56
|
-
|
57
|
-
b.use :input, class: 'form-control'
|
58
|
-
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
59
|
-
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def configure_vertical_file_input_wrapper(config)
|
64
|
-
config.wrappers :vertical_file_input, tag: 'div', class: 'form-group',
|
65
|
-
error_class: 'has-error' do |b|
|
66
|
-
b.use :html5
|
67
|
-
b.use :placeholder
|
68
|
-
b.optional :maxlength
|
69
|
-
b.optional :readonly
|
70
|
-
b.use :label, class: 'control-label'
|
71
|
-
|
72
|
-
b.use :input
|
73
|
-
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
74
|
-
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def configure_vertical_boolean_wrapper(config)
|
79
|
-
config.wrappers :vertical_boolean, tag: 'div', class: 'form-group',
|
80
|
-
error_class: 'has-error' do |b|
|
81
|
-
b.use :html5
|
82
|
-
b.optional :readonly
|
83
|
-
|
84
|
-
b.wrapper tag: 'div', class: 'checkbox' do |ba|
|
85
|
-
ba.use :label_input
|
86
|
-
end
|
87
|
-
|
88
|
-
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
89
|
-
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def configure_vertical_radio_and_checkboxes_wrapper(config)
|
94
|
-
config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group',
|
95
|
-
error_class: 'has-error' do |b|
|
96
|
-
b.use :html5
|
97
|
-
b.optional :readonly
|
98
|
-
b.use :label, class: 'control-label'
|
99
|
-
b.use :input
|
100
|
-
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
101
|
-
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def configure_horizontal_form_wrapper(config)
|
106
|
-
config.wrappers :horizontal_form, tag: 'div', class: 'form-group',
|
107
|
-
error_class: 'has-error' do |b|
|
108
|
-
b.use :html5
|
109
|
-
b.use :placeholder
|
110
|
-
b.optional :maxlength
|
111
|
-
b.optional :pattern
|
112
|
-
b.optional :min_max
|
113
|
-
b.optional :readonly
|
114
|
-
b.use :label, class: 'col-sm-3 control-label'
|
115
|
-
|
116
|
-
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
117
|
-
ba.use :input, class: 'form-control'
|
118
|
-
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
119
|
-
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def configure_horizontal_file_input_wrapper(config)
|
125
|
-
config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group',
|
126
|
-
error_class: 'has-error' do |b|
|
127
|
-
b.use :html5
|
128
|
-
b.use :placeholder
|
129
|
-
b.optional :maxlength
|
130
|
-
b.optional :readonly
|
131
|
-
b.use :label, class: 'col-sm-3 control-label'
|
132
|
-
|
133
|
-
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
134
|
-
ba.use :input
|
135
|
-
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
136
|
-
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def configure_horizontal_boolean_wrapper(config)
|
142
|
-
config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group',
|
143
|
-
error_class: 'has-error' do |b|
|
144
|
-
b.use :html5
|
145
|
-
b.optional :readonly
|
146
|
-
|
147
|
-
b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr|
|
148
|
-
wr.wrapper tag: 'div', class: 'checkbox' do |ba|
|
149
|
-
ba.use :label_input, class: 'col-sm-9'
|
150
|
-
end
|
151
|
-
|
152
|
-
wr.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
153
|
-
wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def configure_horizontal_radio_and_checkboxes_wrapper(config)
|
159
|
-
config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group',
|
160
|
-
error_class: 'has-error' do |b|
|
161
|
-
b.use :html5
|
162
|
-
b.optional :readonly
|
163
|
-
|
164
|
-
b.use :label, class: 'col-sm-3 control-label'
|
165
|
-
|
166
|
-
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
167
|
-
ba.use :input
|
168
|
-
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
169
|
-
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def configure_inline_form_wrapper(config)
|
175
|
-
config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
176
|
-
b.use :html5
|
177
|
-
b.use :placeholder
|
178
|
-
b.optional :maxlength
|
179
|
-
b.optional :pattern
|
180
|
-
b.optional :min_max
|
181
|
-
b.optional :readonly
|
182
|
-
b.use :label, class: 'sr-only'
|
183
|
-
|
184
|
-
b.use :input, class: 'form-control'
|
185
|
-
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
186
|
-
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
1
|
+
# Handles configuration Simple Form with Bootstrap defaults.
|
2
|
+
module SimpleForm::Bootstrap::Setup
|
3
|
+
def setup
|
4
|
+
super do |config|
|
5
|
+
yield config
|
6
|
+
configure_simple_form(config)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def configure_simple_form(config)
|
13
|
+
config.error_notification_tag = :div
|
14
|
+
config.error_notification_class = 'alert alert-danger'
|
15
|
+
config.button_class = 'btn'
|
16
|
+
config.boolean_style = :nested
|
17
|
+
config.boolean_label_class = nil
|
18
|
+
|
19
|
+
configure_wrappers(config)
|
20
|
+
|
21
|
+
# Wrappers for forms and inputs using the Bootstrap toolkit.
|
22
|
+
# Check the Bootstrap docs (http://getbootstrap.com)
|
23
|
+
# to learn about the different styles for forms and inputs,
|
24
|
+
# buttons and other elements.
|
25
|
+
config.default_wrapper = :vertical_form
|
26
|
+
config.wrapper_mappings = {
|
27
|
+
check_boxes: :vertical_radio_and_checkboxes,
|
28
|
+
radio_buttons: :vertical_radio_and_checkboxes,
|
29
|
+
file: :vertical_file_input,
|
30
|
+
boolean: :vertical_boolean,
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def configure_wrappers(config)
|
35
|
+
configure_vertical_form_wrapper(config)
|
36
|
+
configure_vertical_file_input_wrapper(config)
|
37
|
+
configure_vertical_boolean_wrapper(config)
|
38
|
+
configure_vertical_radio_and_checkboxes_wrapper(config)
|
39
|
+
configure_horizontal_form_wrapper(config)
|
40
|
+
configure_horizontal_file_input_wrapper(config)
|
41
|
+
configure_horizontal_boolean_wrapper(config)
|
42
|
+
configure_horizontal_radio_and_checkboxes_wrapper(config)
|
43
|
+
configure_inline_form_wrapper(config)
|
44
|
+
end
|
45
|
+
|
46
|
+
def configure_vertical_form_wrapper(config)
|
47
|
+
config.wrappers :vertical_form, tag: 'div', class: 'form-group',
|
48
|
+
error_class: 'has-error' do |b|
|
49
|
+
b.use :html5
|
50
|
+
b.use :placeholder
|
51
|
+
b.optional :maxlength
|
52
|
+
b.optional :pattern
|
53
|
+
b.optional :min_max
|
54
|
+
b.optional :readonly
|
55
|
+
b.use :label, class: 'control-label'
|
56
|
+
|
57
|
+
b.use :input, class: 'form-control'
|
58
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
59
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def configure_vertical_file_input_wrapper(config)
|
64
|
+
config.wrappers :vertical_file_input, tag: 'div', class: 'form-group',
|
65
|
+
error_class: 'has-error' do |b|
|
66
|
+
b.use :html5
|
67
|
+
b.use :placeholder
|
68
|
+
b.optional :maxlength
|
69
|
+
b.optional :readonly
|
70
|
+
b.use :label, class: 'control-label'
|
71
|
+
|
72
|
+
b.use :input
|
73
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
74
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def configure_vertical_boolean_wrapper(config)
|
79
|
+
config.wrappers :vertical_boolean, tag: 'div', class: 'form-group',
|
80
|
+
error_class: 'has-error' do |b|
|
81
|
+
b.use :html5
|
82
|
+
b.optional :readonly
|
83
|
+
|
84
|
+
b.wrapper tag: 'div', class: 'checkbox' do |ba|
|
85
|
+
ba.use :label_input
|
86
|
+
end
|
87
|
+
|
88
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
89
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def configure_vertical_radio_and_checkboxes_wrapper(config)
|
94
|
+
config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group',
|
95
|
+
error_class: 'has-error' do |b|
|
96
|
+
b.use :html5
|
97
|
+
b.optional :readonly
|
98
|
+
b.use :label, class: 'control-label'
|
99
|
+
b.use :input
|
100
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
101
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def configure_horizontal_form_wrapper(config)
|
106
|
+
config.wrappers :horizontal_form, tag: 'div', class: 'form-group',
|
107
|
+
error_class: 'has-error' do |b|
|
108
|
+
b.use :html5
|
109
|
+
b.use :placeholder
|
110
|
+
b.optional :maxlength
|
111
|
+
b.optional :pattern
|
112
|
+
b.optional :min_max
|
113
|
+
b.optional :readonly
|
114
|
+
b.use :label, class: 'col-sm-3 control-label'
|
115
|
+
|
116
|
+
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
117
|
+
ba.use :input, class: 'form-control'
|
118
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
119
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def configure_horizontal_file_input_wrapper(config)
|
125
|
+
config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group',
|
126
|
+
error_class: 'has-error' do |b|
|
127
|
+
b.use :html5
|
128
|
+
b.use :placeholder
|
129
|
+
b.optional :maxlength
|
130
|
+
b.optional :readonly
|
131
|
+
b.use :label, class: 'col-sm-3 control-label'
|
132
|
+
|
133
|
+
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
134
|
+
ba.use :input
|
135
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
136
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def configure_horizontal_boolean_wrapper(config)
|
142
|
+
config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group',
|
143
|
+
error_class: 'has-error' do |b|
|
144
|
+
b.use :html5
|
145
|
+
b.optional :readonly
|
146
|
+
|
147
|
+
b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr|
|
148
|
+
wr.wrapper tag: 'div', class: 'checkbox' do |ba|
|
149
|
+
ba.use :label_input, class: 'col-sm-9'
|
150
|
+
end
|
151
|
+
|
152
|
+
wr.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
153
|
+
wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def configure_horizontal_radio_and_checkboxes_wrapper(config)
|
159
|
+
config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group',
|
160
|
+
error_class: 'has-error' do |b|
|
161
|
+
b.use :html5
|
162
|
+
b.optional :readonly
|
163
|
+
|
164
|
+
b.use :label, class: 'col-sm-3 control-label'
|
165
|
+
|
166
|
+
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
167
|
+
ba.use :input
|
168
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
169
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def configure_inline_form_wrapper(config)
|
175
|
+
config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
176
|
+
b.use :html5
|
177
|
+
b.use :placeholder
|
178
|
+
b.optional :maxlength
|
179
|
+
b.optional :pattern
|
180
|
+
b.optional :min_max
|
181
|
+
b.optional :readonly
|
182
|
+
b.use :label, class: 'sr-only'
|
183
|
+
|
184
|
+
b.use :input, class: 'form-control'
|
185
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
186
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module SimpleForm; end
|
2
|
-
module SimpleForm::Bootstrap
|
3
|
-
VERSION = '1.1.
|
4
|
-
end
|
1
|
+
module SimpleForm; end
|
2
|
+
module SimpleForm::Bootstrap
|
3
|
+
VERSION = '1.1.2'
|
4
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form-bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Low
|
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
requirements: []
|
193
193
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.4.
|
194
|
+
rubygems_version: 2.4.8
|
195
195
|
signing_key:
|
196
196
|
specification_version: 4
|
197
197
|
summary: Initialises Simple Form to automatically produce Bootstrap 3-friendly markup.
|