simple_form 3.1.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +67 -0
- data/MIT-LICENSE +1 -1
- data/README.md +70 -31
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +5 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +19 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +5 -2
- data/lib/simple_form/action_view_extensions/form_helper.rb +3 -1
- data/lib/simple_form/components/html5.rb +14 -4
- data/lib/simple_form/components/labels.rb +1 -1
- data/lib/simple_form/components/maxlength.rb +17 -4
- data/lib/simple_form/components/minlength.rb +47 -0
- data/lib/simple_form/components.rb +1 -0
- data/lib/simple_form/form_builder.rb +17 -9
- data/lib/simple_form/inputs/base.rb +12 -10
- data/lib/simple_form/inputs/boolean_input.rb +11 -2
- data/lib/simple_form/inputs/collection_input.rb +4 -3
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +1 -1
- data/lib/simple_form/inputs/date_time_input.rb +12 -8
- data/lib/simple_form/inputs/password_input.rb +1 -1
- data/lib/simple_form/inputs/string_input.rb +1 -1
- data/lib/simple_form/inputs/text_input.rb +1 -1
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form.rb +1 -4
- data/test/form_builder/error_test.rb +32 -9
- data/test/form_builder/general_test.rb +40 -8
- data/test/form_builder/input_field_test.rb +53 -67
- data/test/form_builder/label_test.rb +19 -2
- data/test/form_builder/wrapper_test.rb +43 -11
- data/test/inputs/boolean_input_test.rb +18 -0
- data/test/inputs/datetime_input_test.rb +15 -2
- data/test/inputs/discovery_test.rb +1 -0
- data/test/inputs/numeric_input_test.rb +3 -0
- data/test/inputs/priority_input_test.rb +10 -2
- data/test/inputs/required_test.rb +44 -0
- data/test/inputs/string_input_test.rb +20 -12
- data/test/inputs/text_input_test.rb +12 -0
- data/test/support/misc_helpers.rb +22 -1
- data/test/support/mock_controller.rb +3 -1
- data/test/support/models.rb +41 -7
- data/test/test_helper.rb +6 -0
- metadata +24 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21876f0dc22464c3d3cc192c6cb1b387d87a3ffa
|
4
|
+
data.tar.gz: 5dca755be1ecf07cf96360b81c338333787976fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdda2693ca2da6c6b33e393b960969c46de2a1fbea4475cb412429020bb029c4ce1e6fb210e7bfeb6f7e5d19630b9b68f6f89f29eaf02cb200ecf36d22d3ff60
|
7
|
+
data.tar.gz: 912d804b0b3d7b832b7ddc1a1f3e1a57a88fe5ed2d9907d472bd12a3882e1b1b2442e0eae2a95dd9abaa1fa2f4cd74832f6f80ed17144162d6b528ce7d5856ee
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,70 @@
|
|
1
|
+
## Unreleased
|
2
|
+
|
3
|
+
## 3.5.0
|
4
|
+
|
5
|
+
* Updated gem dependency to support Rails 5.1.x.
|
6
|
+
|
7
|
+
## 3.4.0
|
8
|
+
|
9
|
+
* Removed Ruby 2.4.0 `Integer` unification deprecation warning.
|
10
|
+
* Removed EOL Ruby 1.9.3 from the build matrix.
|
11
|
+
* Added `minlength` component.
|
12
|
+
* `boolean_label_class` can be set on a per-input basis.
|
13
|
+
|
14
|
+
## 3.3.1
|
15
|
+
|
16
|
+
### Bug fix
|
17
|
+
|
18
|
+
* Fix support for symbols when looking up types with `ActiveModel::Type`.
|
19
|
+
|
20
|
+
## 3.3.0
|
21
|
+
|
22
|
+
### enhancements
|
23
|
+
* Add the `aria-invalid` attribute on inputs with errors.
|
24
|
+
* Added support for the new `ActiveModel::Type` API over Active Record's
|
25
|
+
column objects.
|
26
|
+
|
27
|
+
### bug fix
|
28
|
+
* Fix `merge_wrapper_options` to correctly merge options with duplicated keys. [@herminiotorres](https://github.com/herminiotorres)
|
29
|
+
Closes [#1278](https://github.com/plataformatec/simple_form/issues/1278).
|
30
|
+
|
31
|
+
## 3.2.1
|
32
|
+
|
33
|
+
### enhancements
|
34
|
+
* Updated gem dependency to support Rails 5.0.x.
|
35
|
+
|
36
|
+
## 3.2.0
|
37
|
+
|
38
|
+
### bug fix
|
39
|
+
* Improve performance of input generation by disabling support for `_html` translations. This reverts the feature introduced on the 3.1.0 branch
|
40
|
+
|
41
|
+
## 3.1.1
|
42
|
+
|
43
|
+
### enhancements
|
44
|
+
* Add the `disabled_class` to the label when the input is disabled. [@rhodrid](https://github.com/rhodrid)
|
45
|
+
|
46
|
+
### bug fix
|
47
|
+
* Make it possible to override `required` value that was previously set in the wrapper. [@nashby](https://github.com/nashby)
|
48
|
+
|
49
|
+
* `date/time/datetime` inputs now correctly generate the label `for` attribute when
|
50
|
+
HTML5 compatibility is explicitly enabled. [@ericsullivan](https://github.com/ericsullivan)
|
51
|
+
|
52
|
+
* The datetime, date, and time inputs now have a nice format by default on bootstrap.
|
53
|
+
[@ulissesalmeida](https://github.com/ulissesalmeida) [@eltonchrls](https://github.com/eltonchrls)
|
54
|
+
|
55
|
+
* Now it is possible to set custom input mappings for collections.
|
56
|
+
|
57
|
+
Example:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
# On configuration:
|
61
|
+
config.input_mappings = { /gender$/ => :check_boxes }
|
62
|
+
|
63
|
+
# On form:
|
64
|
+
f.input :gender, collection: [:male, :female]
|
65
|
+
```
|
66
|
+
[strangeworks](https://github.com/strangeworks)
|
67
|
+
|
1
68
|
## 3.1.0
|
2
69
|
|
3
70
|
### enhancements
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2009-
|
1
|
+
Copyright (c) 2009-2016 Plataformatec http://plataformatec.com.br/
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -32,13 +32,6 @@ Run the generator:
|
|
32
32
|
rails generate simple_form:install
|
33
33
|
```
|
34
34
|
|
35
|
-
Also, if you want to use the country select, you will need the
|
36
|
-
[country_select gem](https://rubygems.org/gems/country_select), add it to your Gemfile:
|
37
|
-
|
38
|
-
```ruby
|
39
|
-
gem 'country_select'
|
40
|
-
```
|
41
|
-
|
42
35
|
### Bootstrap
|
43
36
|
|
44
37
|
**Simple Form** can be easily integrated to the [Bootstrap](http://getbootstrap.com/).
|
@@ -70,6 +63,22 @@ You will need to provide your own CSS styles for hints.
|
|
70
63
|
|
71
64
|
Please see the [instructions on how to install Foundation in a Rails app](http://foundation.zurb.com/docs/applications.html).
|
72
65
|
|
66
|
+
### Country Select
|
67
|
+
|
68
|
+
If you want to use the country select, you will need the
|
69
|
+
[country_select gem](https://rubygems.org/gems/country_select), add it to your Gemfile:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
gem 'country_select'
|
73
|
+
```
|
74
|
+
|
75
|
+
If you don't want to use the gem you can easily override this behaviour by mapping the
|
76
|
+
country inputs to something else, with a line like this in your `simple_form.rb` initializer:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
config.input_mappings = { /country/ => :string }
|
80
|
+
```
|
81
|
+
|
73
82
|
## Usage
|
74
83
|
|
75
84
|
**Simple Form** was designed to be customized as you need to. Basically it's a stack of components that
|
@@ -91,12 +100,12 @@ To start using **Simple Form** you just have to use the helper it provides:
|
|
91
100
|
This will generate an entire form with labels for user name and password as well, and render errors
|
92
101
|
by default when you render the form with invalid data (after submitting for example).
|
93
102
|
|
94
|
-
You can overwrite the default label by passing it to the input method. You can also add a hint
|
95
|
-
even a placeholder. For boolean inputs, you can add an inline label as well:
|
103
|
+
You can overwrite the default label by passing it to the input method. You can also add a hint,
|
104
|
+
an error, or even a placeholder. For boolean inputs, you can add an inline label as well:
|
96
105
|
|
97
106
|
```erb
|
98
107
|
<%= simple_form_for @user do |f| %>
|
99
|
-
<%= f.input :username, label: 'Your username please' %>
|
108
|
+
<%= f.input :username, label: 'Your username please', error: 'Username is mandatory, please specify one' %>
|
100
109
|
<%= f.input :password, hint: 'No special characters.' %>
|
101
110
|
<%= f.input :email, placeholder: 'user@domain.com' %>
|
102
111
|
<%= f.input :remember_me, inline_label: 'Yes, remember me' %>
|
@@ -104,7 +113,7 @@ even a placeholder. For boolean inputs, you can add an inline label as well:
|
|
104
113
|
<% end %>
|
105
114
|
```
|
106
115
|
|
107
|
-
In some cases you may want to disable labels, hints or
|
116
|
+
In some cases you may want to disable labels, hints or errors. Or you may want to configure the html
|
108
117
|
of any of them:
|
109
118
|
|
110
119
|
```erb
|
@@ -155,8 +164,9 @@ any html attribute to that wrapper as well using the `:wrapper_html` option, lik
|
|
155
164
|
|
156
165
|
Required fields are marked with an * prepended to their labels.
|
157
166
|
|
158
|
-
By default all inputs are required. When the form object
|
159
|
-
|
167
|
+
By default all inputs are required. When the form object includes `ActiveModel::Validations`
|
168
|
+
(which, for example, happens with Active Record models), fields are required only when there is `presence` validation.
|
169
|
+
Otherwise, **Simple Form** will mark fields as optional. For performance reasons, this
|
160
170
|
detection is skipped on validations that make use of conditional options, such as `:if` and `:unless`.
|
161
171
|
|
162
172
|
And of course, the `required` property of any input can be overwritten as needed:
|
@@ -204,7 +214,7 @@ the wrapper as well:
|
|
204
214
|
<% end %>
|
205
215
|
```
|
206
216
|
|
207
|
-
**Simple Form**
|
217
|
+
**Simple Form** inputs accept the same options as their corresponding input type helper in Rails:
|
208
218
|
|
209
219
|
```erb
|
210
220
|
<%= simple_form_for @user do |f| %>
|
@@ -259,7 +269,6 @@ end
|
|
259
269
|
```
|
260
270
|
|
261
271
|
For check boxes and radio buttons you can remove the label changing `boolean_style` from default value `:nested` to `:inline`.
|
262
|
-
Also, `item_wrapper_tag` will not work when `boolean_style` is set to `:nested`.
|
263
272
|
|
264
273
|
Example:
|
265
274
|
|
@@ -315,12 +324,16 @@ Collection inputs accept two other options beside collections:
|
|
315
324
|
|
316
325
|
Those methods are useful to manipulate the given collection. Both of these options also accept
|
317
326
|
lambda/procs in case you want to calculate the value or label in a special way eg. custom
|
318
|
-
translation.
|
319
|
-
|
327
|
+
translation. You can also define a `to_label` method on your model as **Simple Form** will search for
|
328
|
+
and use `:to_label` as a `:label_method` first if it is found. All other options given are sent
|
329
|
+
straight to the underlying helper. For example, you can give prompt as:
|
320
330
|
|
321
331
|
```ruby
|
322
|
-
f.input :age, collection: 18..60, prompt: "Select your age"
|
332
|
+
f.input :age, collection: 18..60, prompt: "Select your age", selected: 21
|
323
333
|
```
|
334
|
+
Extra options are passed into helper [`collection_select`](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select).
|
335
|
+
|
336
|
+
You may also find it useful to explicitly pass a value to the optional `:selected`, especially if passing a collection of nested objects.
|
324
337
|
|
325
338
|
It is also possible to create grouped collection selects, that will use the html *optgroup* tags, like this:
|
326
339
|
|
@@ -404,7 +417,7 @@ The association helper just invokes `input` under the hood, so all options avail
|
|
404
417
|
the collection by hand, all together with the prompt:
|
405
418
|
|
406
419
|
```ruby
|
407
|
-
f.association :company, collection: Company.active.
|
420
|
+
f.association :company, collection: Company.active.order(:name), prompt: "Choose a Company"
|
408
421
|
```
|
409
422
|
|
410
423
|
In case you want to declare different labels and values:
|
@@ -435,6 +448,16 @@ The button method also accepts optional parameters, that are delegated to the un
|
|
435
448
|
<%= f.button :submit, "Custom Button Text", class: "my-button" %>
|
436
449
|
```
|
437
450
|
|
451
|
+
To create a `<button>` element, use the following syntax:
|
452
|
+
|
453
|
+
```erb
|
454
|
+
<%= f.button :button, "Custom Button Text" %>
|
455
|
+
|
456
|
+
<%= f.button :button do %>
|
457
|
+
Custom Button Text
|
458
|
+
<% end %>
|
459
|
+
```
|
460
|
+
|
438
461
|
### Wrapping Rails Form Helpers
|
439
462
|
|
440
463
|
Say you wanted to use a rails form helper but still wrap it in **Simple Form** goodness? You can, by
|
@@ -660,7 +683,7 @@ en:
|
|
660
683
|
age: 'Rather not say'
|
661
684
|
prompts:
|
662
685
|
user:
|
663
|
-
|
686
|
+
role: 'Select your role'
|
664
687
|
```
|
665
688
|
|
666
689
|
And your forms will use this information to render the components for you.
|
@@ -715,16 +738,16 @@ For `:prompt` and `:include_blank` the I18n lookup is optional and to enable it
|
|
715
738
|
`:translate` as value.
|
716
739
|
|
717
740
|
```ruby
|
718
|
-
f.input :
|
741
|
+
f.input :role, prompt: :translate
|
719
742
|
```
|
720
743
|
|
721
744
|
**Simple Form** also has support for translating options in collection helpers. For instance, given a
|
722
|
-
User with a `:
|
723
|
-
that would post either `
|
745
|
+
User with a `:role` attribute, you might want to create a select box showing translated labels
|
746
|
+
that would post either `:admin` or `:editor` as value. With **Simple Form** you could create an input
|
724
747
|
like this:
|
725
748
|
|
726
749
|
```ruby
|
727
|
-
f.input :
|
750
|
+
f.input :role, collection: [:admin, :editor]
|
728
751
|
```
|
729
752
|
|
730
753
|
And **Simple Form** will try a lookup like this in your locale file, to find the right labels to show:
|
@@ -734,9 +757,9 @@ en:
|
|
734
757
|
simple_form:
|
735
758
|
options:
|
736
759
|
user:
|
737
|
-
|
738
|
-
|
739
|
-
|
760
|
+
role:
|
761
|
+
admin: 'Administrator'
|
762
|
+
editor: 'Editor'
|
740
763
|
```
|
741
764
|
|
742
765
|
You can also use the `defaults` key as you would do with labels, hints and placeholders. It is
|
@@ -789,6 +812,22 @@ object itself. Thus, similarly, if a form for an `Admin::User` object is defined
|
|
789
812
|
`simple_form_for @admin_user, as: :some_user`, **Simple Form** will look for translations
|
790
813
|
under `some_user` instead of `admin_user`.
|
791
814
|
|
815
|
+
When translating `simple_fields_for` attributes be sure to use the same name you pass to it, e.g. `simple_fields_for :posts` should be placed under `posts` not `post`:
|
816
|
+
|
817
|
+
```yaml
|
818
|
+
en:
|
819
|
+
simple_form:
|
820
|
+
labels:
|
821
|
+
posts:
|
822
|
+
title: 'Post title'
|
823
|
+
hints:
|
824
|
+
posts:
|
825
|
+
title: 'A good title'
|
826
|
+
placeholders:
|
827
|
+
posts:
|
828
|
+
title: 'Once upon a time...'
|
829
|
+
```
|
830
|
+
|
792
831
|
## Configuration
|
793
832
|
|
794
833
|
**Simple Form** has several configuration options. You can read and change them in the initializer
|
@@ -947,8 +986,8 @@ required attribute to force a value into an input and will prevent form submissi
|
|
947
986
|
Depending on the design of the application this may or may not be desired. In many cases it can
|
948
987
|
break existing UI's.
|
949
988
|
|
950
|
-
It is possible to disable all HTML 5 extensions in **Simple Form** removing the `html5`
|
951
|
-
from the wrapper used to render the inputs.
|
989
|
+
It is possible to disable all HTML 5 extensions in **Simple Form** by removing the `html5`
|
990
|
+
component from the wrapper used to render the inputs.
|
952
991
|
|
953
992
|
For example, change:
|
954
993
|
|
@@ -1018,7 +1057,7 @@ http://rubydoc.info/github/plataformatec/simple_form/master/frames
|
|
1018
1057
|
### Bug reports
|
1019
1058
|
|
1020
1059
|
If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as
|
1021
|
-
possible to help us fixing the
|
1060
|
+
possible to help us in fixing the potential bug. We also encourage you to help even more by forking and
|
1022
1061
|
sending us a pull request.
|
1023
1062
|
|
1024
1063
|
https://github.com/plataformatec/simple_form/issues
|
@@ -1037,7 +1076,7 @@ https://github.com/plataformatec/simple_form/issues
|
|
1037
1076
|
|
1038
1077
|
## License
|
1039
1078
|
|
1040
|
-
MIT License. Copyright 2009-
|
1079
|
+
MIT License. Copyright 2009-2016 Plataformatec. http://plataformatec.com.br
|
1041
1080
|
|
1042
1081
|
You are not granted rights or licenses to the trademarks of the Plataformatec, including without
|
1043
1082
|
limitation the Simple Form name or logo.
|
@@ -28,8 +28,12 @@ SimpleForm.setup do |config|
|
|
28
28
|
# extensions by default, you can change `b.optional` to `b.use`.
|
29
29
|
|
30
30
|
# Calculates maxlength from length validations for string inputs
|
31
|
+
# and/or database column lengths
|
31
32
|
b.optional :maxlength
|
32
33
|
|
34
|
+
# Calculate minlength from length validations for string inputs
|
35
|
+
b.optional :minlength
|
36
|
+
|
33
37
|
# Calculates pattern from format validations for string inputs
|
34
38
|
b.optional :pattern
|
35
39
|
|
@@ -90,8 +94,7 @@ SimpleForm.setup do |config|
|
|
90
94
|
# config.collection_wrapper_class = nil
|
91
95
|
|
92
96
|
# You can wrap each item in a collection of radio/check boxes with a tag,
|
93
|
-
# defaulting to :span.
|
94
|
-
# SimpleForm will force this option to be a label.
|
97
|
+
# defaulting to :span.
|
95
98
|
# config.item_wrapper_tag = :span
|
96
99
|
|
97
100
|
# You can define a class to use in all item wrappers. Defaulting to none.
|
@@ -8,6 +8,7 @@ SimpleForm.setup do |config|
|
|
8
8
|
b.use :html5
|
9
9
|
b.use :placeholder
|
10
10
|
b.optional :maxlength
|
11
|
+
b.optional :minlength
|
11
12
|
b.optional :pattern
|
12
13
|
b.optional :min_max
|
13
14
|
b.optional :readonly
|
@@ -22,6 +23,7 @@ SimpleForm.setup do |config|
|
|
22
23
|
b.use :html5
|
23
24
|
b.use :placeholder
|
24
25
|
b.optional :maxlength
|
26
|
+
b.optional :minlength
|
25
27
|
b.optional :readonly
|
26
28
|
b.use :label, class: 'control-label'
|
27
29
|
|
@@ -55,6 +57,7 @@ SimpleForm.setup do |config|
|
|
55
57
|
b.use :html5
|
56
58
|
b.use :placeholder
|
57
59
|
b.optional :maxlength
|
60
|
+
b.optional :minlength
|
58
61
|
b.optional :pattern
|
59
62
|
b.optional :min_max
|
60
63
|
b.optional :readonly
|
@@ -71,6 +74,7 @@ SimpleForm.setup do |config|
|
|
71
74
|
b.use :html5
|
72
75
|
b.use :placeholder
|
73
76
|
b.optional :maxlength
|
77
|
+
b.optional :minlength
|
74
78
|
b.optional :readonly
|
75
79
|
b.use :label, class: 'col-sm-3 control-label'
|
76
80
|
|
@@ -87,7 +91,7 @@ SimpleForm.setup do |config|
|
|
87
91
|
|
88
92
|
b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr|
|
89
93
|
wr.wrapper tag: 'div', class: 'checkbox' do |ba|
|
90
|
-
ba.use :label_input
|
94
|
+
ba.use :label_input
|
91
95
|
end
|
92
96
|
|
93
97
|
wr.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
@@ -112,6 +116,7 @@ SimpleForm.setup do |config|
|
|
112
116
|
b.use :html5
|
113
117
|
b.use :placeholder
|
114
118
|
b.optional :maxlength
|
119
|
+
b.optional :minlength
|
115
120
|
b.optional :pattern
|
116
121
|
b.optional :min_max
|
117
122
|
b.optional :readonly
|
@@ -122,6 +127,16 @@ SimpleForm.setup do |config|
|
|
122
127
|
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
123
128
|
end
|
124
129
|
|
130
|
+
config.wrappers :multi_select, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
131
|
+
b.use :html5
|
132
|
+
b.optional :readonly
|
133
|
+
b.use :label, class: 'control-label'
|
134
|
+
b.wrapper tag: 'div', class: 'form-inline' do |ba|
|
135
|
+
ba.use :input, class: 'form-control'
|
136
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
137
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
138
|
+
end
|
139
|
+
end
|
125
140
|
# Wrappers for forms and inputs using the Bootstrap toolkit.
|
126
141
|
# Check the Bootstrap docs (http://getbootstrap.com)
|
127
142
|
# to learn about the different styles for forms and inputs,
|
@@ -132,5 +147,8 @@ SimpleForm.setup do |config|
|
|
132
147
|
radio_buttons: :vertical_radio_and_checkboxes,
|
133
148
|
file: :vertical_file_input,
|
134
149
|
boolean: :vertical_boolean,
|
150
|
+
datetime: :multi_select,
|
151
|
+
date: :multi_select,
|
152
|
+
time: :multi_select
|
135
153
|
}
|
136
154
|
end
|
@@ -4,13 +4,14 @@ SimpleForm.setup do |config|
|
|
4
4
|
# all the grid-related classes)
|
5
5
|
#
|
6
6
|
# Please note that hints are commented out by default since Foundation
|
7
|
-
#
|
7
|
+
# doesn't provide styles for hints. You will need to provide your own CSS styles for hints.
|
8
8
|
# Uncomment them to enable hints.
|
9
9
|
|
10
10
|
config.wrappers :vertical_form, class: :input, hint_class: :field_with_hint, error_class: :error do |b|
|
11
11
|
b.use :html5
|
12
12
|
b.use :placeholder
|
13
13
|
b.optional :maxlength
|
14
|
+
b.optional :minlength
|
14
15
|
b.optional :pattern
|
15
16
|
b.optional :min_max
|
16
17
|
b.optional :readonly
|
@@ -24,6 +25,7 @@ SimpleForm.setup do |config|
|
|
24
25
|
b.use :html5
|
25
26
|
b.use :placeholder
|
26
27
|
b.optional :maxlength
|
28
|
+
b.optional :minlength
|
27
29
|
b.optional :pattern
|
28
30
|
b.optional :min_max
|
29
31
|
b.optional :readonly
|
@@ -65,6 +67,7 @@ SimpleForm.setup do |config|
|
|
65
67
|
b.use :html5
|
66
68
|
b.use :placeholder
|
67
69
|
b.optional :maxlength
|
70
|
+
b.optional :minlength
|
68
71
|
b.optional :pattern
|
69
72
|
b.optional :min_max
|
70
73
|
b.optional :readonly
|
@@ -95,7 +98,7 @@ SimpleForm.setup do |config|
|
|
95
98
|
config.button_class = 'button'
|
96
99
|
|
97
100
|
# Set this to div to make the checkbox and radio properly work
|
98
|
-
# otherwise simple_form adds a label tag instead of a div
|
101
|
+
# otherwise simple_form adds a label tag instead of a div around
|
99
102
|
# the nested label
|
100
103
|
config.item_wrapper_tag = :div
|
101
104
|
|
@@ -7,10 +7,12 @@ module SimpleForm
|
|
7
7
|
|
8
8
|
def html5(wrapper_options = nil)
|
9
9
|
@html5 = true
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
|
11
|
+
input_html_options[:required] = input_html_required_option
|
12
|
+
input_html_options[:'aria-required'] = input_html_aria_required_option
|
13
|
+
|
14
|
+
input_html_options[:'aria-invalid'] = has_errors? || nil
|
15
|
+
|
14
16
|
nil
|
15
17
|
end
|
16
18
|
|
@@ -18,6 +20,14 @@ module SimpleForm
|
|
18
20
|
@html5
|
19
21
|
end
|
20
22
|
|
23
|
+
def input_html_required_option
|
24
|
+
!options[:required].nil? ? required_field? : has_required?
|
25
|
+
end
|
26
|
+
|
27
|
+
def input_html_aria_required_option
|
28
|
+
!options[:required].nil? ? (required_field? || nil) : (has_required? || nil)
|
29
|
+
end
|
30
|
+
|
21
31
|
def has_required?
|
22
32
|
# We need to check browser_validations because
|
23
33
|
# some browsers are still checking required even
|
@@ -42,7 +42,7 @@ module SimpleForm
|
|
42
42
|
|
43
43
|
def label_html_options
|
44
44
|
label_html_classes = SimpleForm.additional_classes_for(:label) {
|
45
|
-
[input_type, required_class, SimpleForm.label_class].compact
|
45
|
+
[input_type, required_class, disabled_class, SimpleForm.label_class].compact
|
46
46
|
}
|
47
47
|
|
48
48
|
label_options = html_options_for(:label, label_html_classes)
|
@@ -15,10 +15,7 @@ module SimpleForm
|
|
15
15
|
maxlength
|
16
16
|
else
|
17
17
|
length_validator = find_length_validator
|
18
|
-
|
19
|
-
if length_validator && !has_tokenizer?(length_validator)
|
20
|
-
length_validator.options[:is] || length_validator.options[:maximum]
|
21
|
-
end
|
18
|
+
maximum_length_value_from(length_validator)
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
@@ -29,6 +26,22 @@ module SimpleForm
|
|
29
26
|
def has_tokenizer?(length_validator)
|
30
27
|
length_validator.options[:tokenizer]
|
31
28
|
end
|
29
|
+
|
30
|
+
# Use validation with tokenizer if version of Rails is less than 5,
|
31
|
+
# if not validate without the tokenizer, if version is greater than Rails 4.
|
32
|
+
if ActionPack::VERSION::STRING < '5'
|
33
|
+
def maximum_length_value_from(length_validator)
|
34
|
+
if length_validator && !has_tokenizer?(length_validator)
|
35
|
+
length_validator.options[:is] || length_validator.options[:maximum]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
elsif ActionPack::VERSION::STRING >= '5'
|
39
|
+
def maximum_length_value_from(length_validator)
|
40
|
+
if length_validator
|
41
|
+
length_validator.options[:is] || length_validator.options[:maximum]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
32
45
|
end
|
33
46
|
end
|
34
47
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module SimpleForm
|
2
|
+
module Components
|
3
|
+
# Needs to be enabled in order to do automatic lookups.
|
4
|
+
module Minlength
|
5
|
+
def minlength(wrapper_options = nil)
|
6
|
+
input_html_options[:minlength] ||= minimum_length_from_validation || limit
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def minimum_length_from_validation
|
13
|
+
minlength = options[:minlength]
|
14
|
+
if minlength.is_a?(String) || minlength.is_a?(Integer)
|
15
|
+
minlength
|
16
|
+
else
|
17
|
+
length_validator = find_length_validator
|
18
|
+
minimum_length_value_from(length_validator)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_length_validator
|
23
|
+
find_validator(:length)
|
24
|
+
end
|
25
|
+
|
26
|
+
def has_tokenizer?(length_validator)
|
27
|
+
length_validator.options[:tokenizer]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Use validation with tokenizer if version of Rails is less than 5,
|
31
|
+
# if not validate without the tokenizer, if version is greater than Rails 4.
|
32
|
+
if ActionPack::VERSION::STRING < '5'
|
33
|
+
def minimum_length_value_from(length_validator)
|
34
|
+
if length_validator && !has_tokenizer?(length_validator)
|
35
|
+
length_validator.options[:is] || length_validator.options[:minimum]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
elsif ActionPack::VERSION::STRING >= '5'
|
39
|
+
def minimum_length_value_from(length_validator)
|
40
|
+
if length_validator
|
41
|
+
length_validator.options[:is] || length_validator.options[:minimum]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|