simple_form 3.5.0 → 4.0.0
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 +4 -4
- data/CHANGELOG.md +40 -0
- data/README.md +203 -31
- data/lib/generators/simple_form/install_generator.rb +1 -0
- data/lib/generators/simple_form/templates/README +3 -3
- data/lib/generators/simple_form/templates/_form.html.erb +2 -0
- data/lib/generators/simple_form/templates/_form.html.haml +2 -0
- data/lib/generators/simple_form/templates/_form.html.slim +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +15 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +358 -73
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +18 -6
- data/lib/simple_form/action_view_extensions/builder.rb +1 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +1 -0
- data/lib/simple_form/components/errors.rb +10 -1
- data/lib/simple_form/components/hints.rb +1 -0
- data/lib/simple_form/components/html5.rb +1 -0
- data/lib/simple_form/components/label_input.rb +2 -1
- data/lib/simple_form/components/labels.rb +11 -4
- data/lib/simple_form/components/maxlength.rb +4 -13
- data/lib/simple_form/components/min_max.rb +1 -0
- data/lib/simple_form/components/minlength.rb +5 -14
- data/lib/simple_form/components/pattern.rb +1 -0
- data/lib/simple_form/components/placeholders.rb +2 -1
- data/lib/simple_form/components/readonly.rb +1 -0
- data/lib/simple_form/components.rb +1 -0
- data/lib/simple_form/error_notification.rb +1 -0
- data/lib/simple_form/form_builder.rb +74 -19
- data/lib/simple_form/helpers/autofocus.rb +1 -0
- data/lib/simple_form/helpers/disabled.rb +1 -0
- data/lib/simple_form/helpers/readonly.rb +1 -0
- data/lib/simple_form/helpers/required.rb +1 -0
- data/lib/simple_form/helpers/validators.rb +2 -1
- data/lib/simple_form/helpers.rb +1 -0
- data/lib/simple_form/i18n_cache.rb +1 -0
- data/lib/simple_form/inputs/base.rb +20 -1
- data/lib/simple_form/inputs/block_input.rb +1 -0
- data/lib/simple_form/inputs/boolean_input.rb +3 -2
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
- data/lib/simple_form/inputs/collection_input.rb +3 -2
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -1
- data/lib/simple_form/inputs/collection_select_input.rb +1 -0
- data/lib/simple_form/inputs/date_time_input.rb +1 -0
- data/lib/simple_form/inputs/file_input.rb +1 -0
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -0
- data/lib/simple_form/inputs/hidden_input.rb +1 -0
- data/lib/simple_form/inputs/numeric_input.rb +1 -0
- data/lib/simple_form/inputs/password_input.rb +1 -0
- data/lib/simple_form/inputs/priority_input.rb +1 -0
- data/lib/simple_form/inputs/range_input.rb +1 -0
- data/lib/simple_form/inputs/string_input.rb +1 -0
- data/lib/simple_form/inputs/text_input.rb +1 -0
- data/lib/simple_form/inputs.rb +1 -0
- data/lib/simple_form/map_type.rb +1 -0
- data/lib/simple_form/railtie.rb +1 -0
- data/lib/simple_form/tags.rb +1 -0
- data/lib/simple_form/version.rb +2 -1
- data/lib/simple_form/wrappers/builder.rb +1 -0
- data/lib/simple_form/wrappers/leaf.rb +2 -1
- data/lib/simple_form/wrappers/many.rb +1 -0
- data/lib/simple_form/wrappers/root.rb +2 -0
- data/lib/simple_form/wrappers/single.rb +2 -1
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form.rb +58 -7
- data/test/action_view_extensions/builder_test.rb +6 -5
- data/test/action_view_extensions/form_helper_test.rb +3 -2
- data/test/components/custom_components_test.rb +62 -0
- data/test/components/label_test.rb +33 -4
- data/test/form_builder/association_test.rb +27 -2
- data/test/form_builder/button_test.rb +1 -0
- data/test/form_builder/error_notification_test.rb +1 -0
- data/test/form_builder/error_test.rb +6 -0
- data/test/form_builder/general_test.rb +44 -3
- data/test/form_builder/hint_test.rb +6 -0
- data/test/form_builder/input_field_test.rb +27 -1
- data/test/form_builder/label_test.rb +9 -3
- data/test/form_builder/wrapper_test.rb +24 -4
- data/test/generators/simple_form_generator_test.rb +4 -3
- data/test/inputs/boolean_input_test.rb +9 -0
- data/test/inputs/collection_check_boxes_input_test.rb +30 -14
- data/test/inputs/collection_radio_buttons_input_test.rb +40 -24
- data/test/inputs/collection_select_input_test.rb +40 -39
- data/test/inputs/datetime_input_test.rb +5 -4
- data/test/inputs/disabled_test.rb +1 -0
- data/test/inputs/discovery_test.rb +1 -0
- data/test/inputs/file_input_test.rb +1 -0
- data/test/inputs/general_test.rb +3 -2
- data/test/inputs/grouped_collection_select_input_test.rb +11 -10
- data/test/inputs/hidden_input_test.rb +1 -0
- data/test/inputs/numeric_input_test.rb +2 -1
- data/test/inputs/priority_input_test.rb +1 -0
- data/test/inputs/readonly_test.rb +1 -0
- data/test/inputs/required_test.rb +1 -0
- data/test/inputs/string_input_test.rb +2 -1
- data/test/inputs/text_input_test.rb +1 -0
- data/test/simple_form_test.rb +1 -0
- data/test/support/discovery_inputs.rb +1 -0
- data/test/support/misc_helpers.rb +16 -1
- data/test/support/mock_controller.rb +4 -0
- data/test/support/models.rb +44 -14
- data/test/test_helper.rb +2 -0
- metadata +5 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bdc43deadddaaf9bc4b3872855d677c5e560066d
|
|
4
|
+
data.tar.gz: 1a58416a2a4977e825f25c345ba41abec78c85a9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9812df086c46e0abe897274ac1260cac8dccb7d906da88f75182efc741a4802931f0c5c8b556dfa1ab0793cf93fe9cd68909d69948cee1f43f26b7a807e3ae29
|
|
7
|
+
data.tar.gz: dca2a8eaf706656f77f5294a18068521aa83a9ab2fbd1e269009e68751e9ea2d2811127d5daa017d137c5c9ec5c74b62bbfaaa3fb002211f6778d09cb19a066c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
## Unreleased
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Enhancements
|
|
6
|
+
* Add bootstrap v4.1 generator template. [@m5o](https://github.com/m5o)
|
|
7
|
+
* Add Rails 5.2 support. [@gobijan](https://github.com/gobijan)
|
|
8
|
+
* Add API to register custom components.[@feliperenan](https://github.com/feliperenan)
|
|
9
|
+
* Allow custom errors classes to inputs.[@feliperenan](https://github.com/feliperenan)
|
|
10
|
+
* Remove support from Rails 4.0, 4.1 and 4.2. [@feliperenan](https://github.com/feliperenan)
|
|
11
|
+
* Add support for citext, hstore, json & jsonb column types. [@swrobel](https://github.com/swrobel)
|
|
12
|
+
* Add :valid_class on input wrapper when value is present and valid [@aeberlin](https://github.com/aeberlin), [@m5o](https://github.com/m5o)
|
|
13
|
+
* Allow :valid_class to inputs when value is present and valid. [@m5o](https://github.com/m5o)
|
|
14
|
+
* Allow validation classes on input_field. [@feliperenan](https://github.com/feliperenan)
|
|
15
|
+
* Add basic ActiveStorage support. [@murb](https://github.com/murb)
|
|
16
|
+
|
|
17
|
+
### Bug fix
|
|
18
|
+
* Fix horizontal form label position, from right to text-right. [@cavpollo](https://github.com/cavpollo)
|
|
19
|
+
* Add base error display alongside existing errors. [@bluefalcon26](https://github.com/bluefalcon26)
|
|
20
|
+
* Silent deprication warning for placeholder_text. [@moofkit](https://github.com/moofkit)
|
|
21
|
+
* Use custom i18n scope for label required html. [@tvdeyen](https://github.com/tvdeyen)
|
|
22
|
+
|
|
23
|
+
## 3.5.1
|
|
24
|
+
|
|
25
|
+
### Enhancements
|
|
26
|
+
* Exclude hidden field when unchecked_value: false. [@fschwahn](https://github.com/fschwahn)
|
|
27
|
+
* Add frozen_string_literal magic comment to several files. [@oniofchaos](https://github.com/oniofchaos)
|
|
28
|
+
* Try convert @object to model in case we got decorated object [@timurvafin](https://github.com/timurvafin)
|
|
29
|
+
- From now, if you are using some object that inherits from `SimpleDelegator`, you must implement
|
|
30
|
+
`def to_model; self; end`. Otherwise, *Simple Form* will convert the decorated object to the model
|
|
31
|
+
since `SimpleDelegator` will delegate it to the model.
|
|
32
|
+
* Code cleanup [@Fornacula](https://github.com/Fornacula)
|
|
33
|
+
|
|
34
|
+
### Bug fix
|
|
35
|
+
* Fix error when the scope from association has parameter. [@feliperenan](https://github.com/feliperenan)
|
|
36
|
+
* Only call `where` on associations when they respond to it. [@anicholson](https://github.com/anicholson)
|
|
37
|
+
* require 'action_pack' before using it. [@etagwerker](https://github.com/etagwerker)
|
|
38
|
+
* Check if Rails.env is defined. [@etagwerker](https://github.com/etagwerker)
|
|
39
|
+
* Fix minlength. [@mameier](https://github.com/mameier)
|
|
40
|
+
* Make errors_on_attribute return [] when not present. [@redrick](https://github.com/redrick)
|
|
41
|
+
* Fix boolean inputs in nested style for label non-string. [@feliperenan](https://github.com/feliperenan)
|
|
42
|
+
|
|
3
43
|
## 3.5.0
|
|
4
44
|
|
|
5
45
|
* Updated gem dependency to support Rails 5.1.x.
|
data/README.md
CHANGED
|
@@ -325,8 +325,18 @@ Collection inputs accept two other options beside collections:
|
|
|
325
325
|
Those methods are useful to manipulate the given collection. Both of these options also accept
|
|
326
326
|
lambda/procs in case you want to calculate the value or label in a special way eg. custom
|
|
327
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.
|
|
329
|
-
|
|
328
|
+
and use `:to_label` as a `:label_method` first if it is found.
|
|
329
|
+
|
|
330
|
+
By default, **Simple Form** will use the first item from an array as the label and the second one as the value.
|
|
331
|
+
If you want to change this behavior you must make it explicit, like this:
|
|
332
|
+
|
|
333
|
+
```erb
|
|
334
|
+
<%= simple_form_for @user do |f| %>
|
|
335
|
+
<%= f.input :gender, as: :radio_buttons, collection: [['0', 'female'], ['1', 'male']], label_method: :second, value_method: :first %>
|
|
336
|
+
<% end %>
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
All other options given are sent straight to the underlying helper. For example, you can give prompt as:
|
|
330
340
|
|
|
331
341
|
```ruby
|
|
332
342
|
f.input :age, collection: 18..60, prompt: "Select your age", selected: 21
|
|
@@ -541,31 +551,35 @@ The following table shows the html element you will get for each attribute
|
|
|
541
551
|
according to its database definition. These defaults can be changed by
|
|
542
552
|
specifying the helper method in the column `Mapping` as the `as:` option.
|
|
543
553
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
554
|
+
Mapping | Generated HTML Element | Database Column Type
|
|
555
|
+
--------------- |--------------------------------------|---------------------
|
|
556
|
+
`boolean` | `input[type=checkbox]` | `boolean`
|
|
557
|
+
`string` | `input[type=text]` | `string`
|
|
558
|
+
`citext` | `input[type=text]` | `citext`
|
|
559
|
+
`email` | `input[type=email]` | `string` with `name =~ /email/`
|
|
560
|
+
`url` | `input[type=url]` | `string` with `name =~ /url/`
|
|
561
|
+
`tel` | `input[type=tel]` | `string` with `name =~ /phone/`
|
|
562
|
+
`password` | `input[type=password]` | `string` with `name =~ /password/`
|
|
563
|
+
`search` | `input[type=search]` | -
|
|
564
|
+
`uuid` | `input[type=text]` | `uuid`
|
|
565
|
+
`text` | `textarea` | `text`
|
|
566
|
+
`hstore` | `textarea` | `hstore`
|
|
567
|
+
`json` | `textarea` | `json`
|
|
568
|
+
`jsonb` | `textarea` | `jsonb`
|
|
569
|
+
`file` | `input[type=file]` | `string` responding to file methods
|
|
570
|
+
`hidden` | `input[type=hidden]` | -
|
|
571
|
+
`integer` | `input[type=number]` | `integer`
|
|
572
|
+
`float` | `input[type=number]` | `float`
|
|
573
|
+
`decimal` | `input[type=number]` | `decimal`
|
|
574
|
+
`range` | `input[type=range]` | -
|
|
575
|
+
`datetime` | `datetime select` | `datetime/timestamp`
|
|
576
|
+
`date` | `date select` | `date`
|
|
577
|
+
`time` | `time select` | `time`
|
|
578
|
+
`select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
|
|
579
|
+
`radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations
|
|
580
|
+
`check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
|
|
581
|
+
`country` | `select` (countries as options) | `string` with `name =~ /country/`
|
|
582
|
+
`time_zone` | `select` (timezones as options) | `string` with `name =~ /time_zone/`
|
|
569
583
|
|
|
570
584
|
## Custom inputs
|
|
571
585
|
|
|
@@ -842,7 +856,8 @@ The syntax looks like this:
|
|
|
842
856
|
|
|
843
857
|
```ruby
|
|
844
858
|
config.wrappers tag: :div, class: :input,
|
|
845
|
-
error_class: :field_with_errors
|
|
859
|
+
error_class: :field_with_errors,
|
|
860
|
+
valid_class: :field_without_errors do |b|
|
|
846
861
|
|
|
847
862
|
# Form extensions
|
|
848
863
|
b.use :html5
|
|
@@ -891,11 +906,12 @@ You can customize _Form components_ passing options to them:
|
|
|
891
906
|
|
|
892
907
|
```ruby
|
|
893
908
|
config.wrappers do |b|
|
|
894
|
-
b.use :label_input, class: 'label-input-class'
|
|
909
|
+
b.use :label_input, class: 'label-input-class', error_class: 'is-invalid', valid_class: 'is-valid'
|
|
895
910
|
end
|
|
896
911
|
```
|
|
897
912
|
|
|
898
|
-
This you set the input and label class to `'label-input-class'
|
|
913
|
+
This you set the input and label class to `'label-input-class'` and will set the class `'is-invalid'`
|
|
914
|
+
when the input has errors and `'is-valid'` if the input is valid.
|
|
899
915
|
|
|
900
916
|
If you want to customize the custom _Form components_ on demand you can give it a name like this:
|
|
901
917
|
|
|
@@ -974,6 +990,92 @@ when the content is present.
|
|
|
974
990
|
end
|
|
975
991
|
```
|
|
976
992
|
|
|
993
|
+
## Custom Components
|
|
994
|
+
|
|
995
|
+
When you use custom wrappers, you might also be looking for a way to add custom components to your
|
|
996
|
+
wrapper. The default components are:
|
|
997
|
+
|
|
998
|
+
```ruby
|
|
999
|
+
:label # The <label> tag alone
|
|
1000
|
+
:input # The <input> tag alone
|
|
1001
|
+
:label_input # The <label> and the <input> tags
|
|
1002
|
+
:hint # The hint for the input
|
|
1003
|
+
:error # The error for the input
|
|
1004
|
+
```
|
|
1005
|
+
|
|
1006
|
+
A custom component might be interesting for you if your views look something like this:
|
|
1007
|
+
|
|
1008
|
+
```erb
|
|
1009
|
+
<%= simple_form_for @blog do |f| %>
|
|
1010
|
+
<div class="row">
|
|
1011
|
+
<div class="span1 number">
|
|
1012
|
+
1
|
|
1013
|
+
</div>
|
|
1014
|
+
<div class="span8">
|
|
1015
|
+
<%= f.input :title %>
|
|
1016
|
+
</div>
|
|
1017
|
+
</div>
|
|
1018
|
+
<div class="row">
|
|
1019
|
+
<div class="span1 number">
|
|
1020
|
+
2
|
|
1021
|
+
</div>
|
|
1022
|
+
<div class="span8">
|
|
1023
|
+
<%= f.input :body, as: :text %>
|
|
1024
|
+
</div>
|
|
1025
|
+
</div>
|
|
1026
|
+
<% end %>
|
|
1027
|
+
```
|
|
1028
|
+
|
|
1029
|
+
A cleaner method to create your views would be:
|
|
1030
|
+
|
|
1031
|
+
```erb
|
|
1032
|
+
<%= simple_form_for @blog, wrapper: :with_numbers do |f| %>
|
|
1033
|
+
<%= f.input :title, number: 1 %>
|
|
1034
|
+
<%= f.input :body, as: :text, number: 2 %>
|
|
1035
|
+
<% end %>
|
|
1036
|
+
```
|
|
1037
|
+
|
|
1038
|
+
To use the number option on the input, first, tells to Simple Form the place where the components
|
|
1039
|
+
will be:
|
|
1040
|
+
|
|
1041
|
+
``` ruby
|
|
1042
|
+
# config/initializers/simple_form.rb
|
|
1043
|
+
Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
|
|
1044
|
+
```
|
|
1045
|
+
|
|
1046
|
+
Create a new component within the path specified above:
|
|
1047
|
+
|
|
1048
|
+
```ruby
|
|
1049
|
+
# lib/components/numbers_component.rb
|
|
1050
|
+
module NumbersComponent
|
|
1051
|
+
# To avoid deprecation warning, you need to make the wrapper_options explicit
|
|
1052
|
+
# even when they won't be used.
|
|
1053
|
+
def number(wrapper_options = nil)
|
|
1054
|
+
@number ||= begin
|
|
1055
|
+
options[:number].to_s.html_safe if options[:number].present?
|
|
1056
|
+
end
|
|
1057
|
+
end
|
|
1058
|
+
end
|
|
1059
|
+
|
|
1060
|
+
SimpleForm.include_component(NumbersComponent)
|
|
1061
|
+
```
|
|
1062
|
+
|
|
1063
|
+
Finally, add a new wrapper to the config/initializers/simple_form.rb file:
|
|
1064
|
+
|
|
1065
|
+
```ruby
|
|
1066
|
+
config.wrappers :with_numbers, tag: 'div', class: 'row', error_class: 'error' do |b|
|
|
1067
|
+
b.use :html5
|
|
1068
|
+
b.use :number, wrap_with: { tag: 'div', class: 'span1 number'}
|
|
1069
|
+
b.wrapper tag: 'div', class: 'span8' do |ba|
|
|
1070
|
+
ba.use :placeholder
|
|
1071
|
+
ba.use :label
|
|
1072
|
+
ba.use :input
|
|
1073
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
|
|
1074
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
|
1075
|
+
end
|
|
1076
|
+
end
|
|
1077
|
+
```
|
|
1078
|
+
|
|
977
1079
|
## HTML 5 Notice
|
|
978
1080
|
|
|
979
1081
|
By default, **Simple Form** will generate input field types and attributes that are supported in HTML5,
|
|
@@ -1039,6 +1141,76 @@ by passing the html5 option:
|
|
|
1039
1141
|
<%= f.input :expires_at, as: :date, html5: true %>
|
|
1040
1142
|
```
|
|
1041
1143
|
|
|
1144
|
+
### Using non Active Record objects
|
|
1145
|
+
|
|
1146
|
+
There are few ways to build forms with objects that don't inherit from Active Record, as
|
|
1147
|
+
follow:
|
|
1148
|
+
|
|
1149
|
+
You can include the module `ActiveModel::Model`.
|
|
1150
|
+
|
|
1151
|
+
```ruby
|
|
1152
|
+
class User
|
|
1153
|
+
include ActiveModel::Model
|
|
1154
|
+
|
|
1155
|
+
attr_accessor :id, :name
|
|
1156
|
+
end
|
|
1157
|
+
```
|
|
1158
|
+
|
|
1159
|
+
If you are using Presenters or Decorators that inherit from `SimpleDelegator` you can delegate
|
|
1160
|
+
it to the model.
|
|
1161
|
+
|
|
1162
|
+
```ruby
|
|
1163
|
+
class UserPresenter < SimpleDelegator
|
|
1164
|
+
# Without that, Simple Form will consider the user model as the object.
|
|
1165
|
+
def to_model
|
|
1166
|
+
self
|
|
1167
|
+
end
|
|
1168
|
+
end
|
|
1169
|
+
```
|
|
1170
|
+
|
|
1171
|
+
You can define all methods required by the helpers.
|
|
1172
|
+
|
|
1173
|
+
```ruby
|
|
1174
|
+
class User
|
|
1175
|
+
extend ActiveModel::Naming
|
|
1176
|
+
|
|
1177
|
+
attr_accessor :id, :name
|
|
1178
|
+
|
|
1179
|
+
def to_model
|
|
1180
|
+
self
|
|
1181
|
+
end
|
|
1182
|
+
|
|
1183
|
+
def to_key
|
|
1184
|
+
id
|
|
1185
|
+
end
|
|
1186
|
+
|
|
1187
|
+
def persisted?
|
|
1188
|
+
false
|
|
1189
|
+
end
|
|
1190
|
+
end
|
|
1191
|
+
```
|
|
1192
|
+
|
|
1193
|
+
If your object doesn't implement those methods, you must make explicit it when you are
|
|
1194
|
+
building the form
|
|
1195
|
+
|
|
1196
|
+
```ruby
|
|
1197
|
+
class User
|
|
1198
|
+
attr_accessor :id, :name
|
|
1199
|
+
|
|
1200
|
+
# The only method required to use the f.submit helper.
|
|
1201
|
+
def persisted?
|
|
1202
|
+
false
|
|
1203
|
+
end
|
|
1204
|
+
end
|
|
1205
|
+
```
|
|
1206
|
+
|
|
1207
|
+
```erb
|
|
1208
|
+
<%= simple_form_for(@user, as: :user, method: :post, url: users_path) do |f| %>
|
|
1209
|
+
<%= f.input :name %>
|
|
1210
|
+
<%= f.submit 'New user' %>
|
|
1211
|
+
<% end %>
|
|
1212
|
+
```
|
|
1213
|
+
|
|
1042
1214
|
## Information
|
|
1043
1215
|
|
|
1044
1216
|
### Google Group
|
|
@@ -1076,7 +1248,7 @@ https://github.com/plataformatec/simple_form/issues
|
|
|
1076
1248
|
|
|
1077
1249
|
## License
|
|
1078
1250
|
|
|
1079
|
-
MIT License. Copyright 2009-
|
|
1251
|
+
MIT License. Copyright 2009-2018 Plataformatec. http://plataformatec.com.br
|
|
1080
1252
|
|
|
1081
1253
|
You are not granted rights or licenses to the trademarks of the Plataformatec, including without
|
|
1082
1254
|
limitation the Simple Form name or logo.
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Be sure to have a copy of the Bootstrap stylesheet available on your
|
|
4
4
|
application, you can get it on http://getbootstrap.com/.
|
|
5
5
|
|
|
6
|
-
Inside your views, use the 'simple_form_for' with
|
|
7
|
-
|
|
6
|
+
Inside your views, use the 'simple_form_for' with the Bootstrap form
|
|
7
|
+
class, '.form-inline', as the following:
|
|
8
8
|
|
|
9
|
-
= simple_form_for(@user, html: { class: 'form-
|
|
9
|
+
= simple_form_for(@user, html: { class: 'form-inline' }) do |form|
|
|
10
10
|
|
|
11
11
|
===============================================================================
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
<%# frozen_string_literal: true %>
|
|
1
2
|
<%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
|
|
2
3
|
<%%= f.error_notification %>
|
|
4
|
+
<%%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
|
|
3
5
|
|
|
4
6
|
<div class="form-inputs">
|
|
5
7
|
<%- attributes.each do |attribute| -%>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
-# frozen_string_literal: true
|
|
1
2
|
= simple_form_for(@<%= singular_table_name %>) do |f|
|
|
2
3
|
= f.error_notification
|
|
4
|
+
= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present?
|
|
3
5
|
|
|
4
6
|
.form-inputs
|
|
5
7
|
<%- attributes.each do |attribute| -%>
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
3
|
+
# Uncomment this and change the path if necessary to include your own
|
|
4
|
+
# components.
|
|
5
|
+
# See https://github.com/plataformatec/simple_form#custom-components to know
|
|
6
|
+
# more about custom components.
|
|
7
|
+
# Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
|
|
8
|
+
#
|
|
1
9
|
# Use this setup block to configure all options available in SimpleForm.
|
|
2
10
|
SimpleForm.setup do |config|
|
|
3
11
|
# Wrappers are used by the form builder to generate a
|
|
@@ -6,7 +14,7 @@ SimpleForm.setup do |config|
|
|
|
6
14
|
# stack. The options given below are used to wrap the
|
|
7
15
|
# whole input.
|
|
8
16
|
config.wrappers :default, class: :input,
|
|
9
|
-
hint_class: :field_with_hint, error_class: :field_with_errors do |b|
|
|
17
|
+
hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b|
|
|
10
18
|
## Extensions enabled by default
|
|
11
19
|
# Any of these extensions can be disabled for a
|
|
12
20
|
# given input by passing: `f.input EXTENSION_NAME => false`.
|
|
@@ -44,6 +52,7 @@ SimpleForm.setup do |config|
|
|
|
44
52
|
b.optional :readonly
|
|
45
53
|
|
|
46
54
|
## Inputs
|
|
55
|
+
# b.use :input, class: 'input', error_class: 'is-invalid', valid_class: 'is-valid'
|
|
47
56
|
b.use :label_input
|
|
48
57
|
b.use :hint, wrap_with: { tag: :span, class: :hint }
|
|
49
58
|
b.use :error, wrap_with: { tag: :span, class: :error }
|
|
@@ -124,7 +133,7 @@ SimpleForm.setup do |config|
|
|
|
124
133
|
config.browser_validations = false
|
|
125
134
|
|
|
126
135
|
# Collection of methods to detect if a file type was given.
|
|
127
|
-
# config.file_methods = [ :mounted_as, :file?, :public_filename ]
|
|
136
|
+
# config.file_methods = [ :mounted_as, :file?, :public_filename :attached? ]
|
|
128
137
|
|
|
129
138
|
# Custom mappings for input types. This should be a hash containing a regexp
|
|
130
139
|
# to match as key, and the input type that will be used when the field name
|
|
@@ -166,4 +175,8 @@ SimpleForm.setup do |config|
|
|
|
166
175
|
|
|
167
176
|
# Defines which i18n scope will be used in Simple Form.
|
|
168
177
|
# config.i18n_scope = 'simple_form'
|
|
178
|
+
|
|
179
|
+
# Defines validation classes to the input_field. By default it's nil.
|
|
180
|
+
# config.input_field_valid_class = 'is-valid'
|
|
181
|
+
# config.input_field_error_class = 'is-invalid'
|
|
169
182
|
end
|