simple_form_nested_fields 0.1.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 +7 -0
- data/.babelrc +3 -0
- data/.gitignore +11 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +244 -0
- data/Guardfile +8 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +190 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/assets/javascripts/simple_form_nested_fields.coffee +32 -0
- data/lib/assets/javascripts/simple_form_nested_fields__links.coffee +49 -0
- data/lib/assets/javascripts/simple_form_nested_fields__sortable.coffee +55 -0
- data/lib/assets/javascripts/sortablejs/1.6.1/index.js +2 -0
- data/lib/config/locales/simple_form_nested_fields.en.yml +5 -0
- data/lib/simple_form_nested_fields.rb +17 -0
- data/lib/simple_form_nested_fields/action_view_extension.rb +15 -0
- data/lib/simple_form_nested_fields/nested_fields_builder.rb +120 -0
- data/lib/simple_form_nested_fields/railtie.rb +9 -0
- data/lib/simple_form_nested_fields/version.rb +3 -0
- data/package.json +40 -0
- data/package/dist/index.js +1924 -0
- data/package/src/__links.coffee +48 -0
- data/package/src/__sortable.coffee +55 -0
- data/package/src/index.js +3 -0
- data/package/src/simple_form_nested_fields.coffee +29 -0
- data/simple_form_nested_fields.gemspec +39 -0
- data/webpack.config.js +44 -0
- data/yarn.lock +5176 -0
- metadata +330 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 968039b20ea8b76c398ebe16d627e5daa039eb4b30955380852f074e12880e02
|
4
|
+
data.tar.gz: c64d8fc0113c9db8788eefc332dae38770d7af4219faffcd2e792470e0ccd6cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a31dab975e4bfb5d04aff1c82f1ea62833c3f45ebf86168fe8b797f7b12be7f9437c2e77657448d8cc83717a097470aedf1033393647085a0d3a6e564ead594d
|
7
|
+
data.tar.gz: 6d8df7ccf3068db6904ca33cef7b9161146b97817dad7c1fbfceecf39e124c66f544ca279b66a838f81f0075145b38e6baa21743c3cc4d25ea41ef06c6979496
|
data/.babelrc
ADDED
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
sudo: required
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.5.1
|
5
|
+
services:
|
6
|
+
- mongodb
|
7
|
+
addons:
|
8
|
+
chrome: stable
|
9
|
+
apt:
|
10
|
+
packages:
|
11
|
+
- chromium-chromedriver
|
12
|
+
before_install:
|
13
|
+
- gem install bundler -v 1.16.1
|
14
|
+
before_script:
|
15
|
+
- ln -s /usr/lib/chromium-browser/chromedriver ~/bin/chromedriver
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
simple_form_nested_fields (0.1.0)
|
5
|
+
coffee-rails
|
6
|
+
simple_form
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
remote: https://rails-assets.org/
|
11
|
+
specs:
|
12
|
+
actioncable (5.2.1)
|
13
|
+
actionpack (= 5.2.1)
|
14
|
+
nio4r (~> 2.0)
|
15
|
+
websocket-driver (>= 0.6.1)
|
16
|
+
actionmailer (5.2.1)
|
17
|
+
actionpack (= 5.2.1)
|
18
|
+
actionview (= 5.2.1)
|
19
|
+
activejob (= 5.2.1)
|
20
|
+
mail (~> 2.5, >= 2.5.4)
|
21
|
+
rails-dom-testing (~> 2.0)
|
22
|
+
actionpack (5.2.1)
|
23
|
+
actionview (= 5.2.1)
|
24
|
+
activesupport (= 5.2.1)
|
25
|
+
rack (~> 2.0)
|
26
|
+
rack-test (>= 0.6.3)
|
27
|
+
rails-dom-testing (~> 2.0)
|
28
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
29
|
+
actionview (5.2.1)
|
30
|
+
activesupport (= 5.2.1)
|
31
|
+
builder (~> 3.1)
|
32
|
+
erubi (~> 1.4)
|
33
|
+
rails-dom-testing (~> 2.0)
|
34
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
35
|
+
activejob (5.2.1)
|
36
|
+
activesupport (= 5.2.1)
|
37
|
+
globalid (>= 0.3.6)
|
38
|
+
activemodel (5.2.1)
|
39
|
+
activesupport (= 5.2.1)
|
40
|
+
activerecord (5.2.1)
|
41
|
+
activemodel (= 5.2.1)
|
42
|
+
activesupport (= 5.2.1)
|
43
|
+
arel (>= 9.0)
|
44
|
+
activestorage (5.2.1)
|
45
|
+
actionpack (= 5.2.1)
|
46
|
+
activerecord (= 5.2.1)
|
47
|
+
marcel (~> 0.3.1)
|
48
|
+
activesupport (5.2.1)
|
49
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
50
|
+
i18n (>= 0.7, < 2)
|
51
|
+
minitest (~> 5.1)
|
52
|
+
tzinfo (~> 1.1)
|
53
|
+
addressable (2.5.2)
|
54
|
+
public_suffix (>= 2.0.2, < 4.0)
|
55
|
+
ansi (1.5.0)
|
56
|
+
arel (9.0.0)
|
57
|
+
bson (4.3.0)
|
58
|
+
builder (3.2.3)
|
59
|
+
capybara (2.18.0)
|
60
|
+
addressable
|
61
|
+
mini_mime (>= 0.1.3)
|
62
|
+
nokogiri (>= 1.3.3)
|
63
|
+
rack (>= 1.0.0)
|
64
|
+
rack-test (>= 0.5.4)
|
65
|
+
xpath (>= 2.0, < 4.0)
|
66
|
+
capybara-screenshot (1.0.21)
|
67
|
+
capybara (>= 1.0, < 4)
|
68
|
+
launchy
|
69
|
+
childprocess (0.9.0)
|
70
|
+
ffi (~> 1.0, >= 1.0.11)
|
71
|
+
coderay (1.1.2)
|
72
|
+
coffee-rails (4.2.2)
|
73
|
+
coffee-script (>= 2.2.0)
|
74
|
+
railties (>= 4.0.0)
|
75
|
+
coffee-script (2.4.1)
|
76
|
+
coffee-script-source
|
77
|
+
execjs
|
78
|
+
coffee-script-source (1.12.2)
|
79
|
+
concurrent-ruby (1.0.5)
|
80
|
+
crass (1.0.4)
|
81
|
+
database_cleaner (1.7.0)
|
82
|
+
erubi (1.7.1)
|
83
|
+
execjs (2.7.0)
|
84
|
+
ffi (1.9.25)
|
85
|
+
formatador (0.2.5)
|
86
|
+
globalid (0.4.1)
|
87
|
+
activesupport (>= 4.2.0)
|
88
|
+
guard (2.14.2)
|
89
|
+
formatador (>= 0.2.4)
|
90
|
+
listen (>= 2.7, < 4.0)
|
91
|
+
lumberjack (>= 1.0.12, < 2.0)
|
92
|
+
nenv (~> 0.1)
|
93
|
+
notiffany (~> 0.0)
|
94
|
+
pry (>= 0.9.12)
|
95
|
+
shellany (~> 0.0)
|
96
|
+
thor (>= 0.18.1)
|
97
|
+
guard-compat (1.2.1)
|
98
|
+
guard-minitest (2.4.6)
|
99
|
+
guard-compat (~> 1.2)
|
100
|
+
minitest (>= 3.0)
|
101
|
+
i18n (1.1.0)
|
102
|
+
concurrent-ruby (~> 1.0)
|
103
|
+
jquery-rails (4.3.3)
|
104
|
+
rails-dom-testing (>= 1, < 3)
|
105
|
+
railties (>= 4.2.0)
|
106
|
+
thor (>= 0.14, < 2.0)
|
107
|
+
launchy (2.4.3)
|
108
|
+
addressable (~> 2.3)
|
109
|
+
listen (3.1.5)
|
110
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
111
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
112
|
+
ruby_dep (~> 1.2)
|
113
|
+
loofah (2.2.2)
|
114
|
+
crass (~> 1.0.2)
|
115
|
+
nokogiri (>= 1.5.9)
|
116
|
+
lumberjack (1.0.13)
|
117
|
+
mail (2.7.0)
|
118
|
+
mini_mime (>= 0.1.1)
|
119
|
+
marcel (0.3.3)
|
120
|
+
mimemagic (~> 0.3.2)
|
121
|
+
method_source (0.9.0)
|
122
|
+
mimemagic (0.3.2)
|
123
|
+
mini_mime (1.0.1)
|
124
|
+
mini_portile2 (2.3.0)
|
125
|
+
minitest (5.11.3)
|
126
|
+
minitest-around (0.4.1)
|
127
|
+
minitest (~> 5.0)
|
128
|
+
minitest-capybara (0.8.2)
|
129
|
+
capybara (~> 2.2)
|
130
|
+
minitest (~> 5.0)
|
131
|
+
rake
|
132
|
+
minitest-metadata (0.6.0)
|
133
|
+
minitest (>= 4.7, < 6.0)
|
134
|
+
minitest-rails (3.0.0)
|
135
|
+
minitest (~> 5.8)
|
136
|
+
railties (~> 5.0)
|
137
|
+
minitest-rails-capybara (3.0.1)
|
138
|
+
capybara (~> 2.7)
|
139
|
+
minitest-capybara (~> 0.8)
|
140
|
+
minitest-metadata (~> 0.6)
|
141
|
+
minitest-rails (~> 3.0)
|
142
|
+
minitest-reporters (1.3.4)
|
143
|
+
ansi
|
144
|
+
builder
|
145
|
+
minitest (>= 5.0)
|
146
|
+
ruby-progressbar
|
147
|
+
mongo (2.6.2)
|
148
|
+
bson (>= 4.3.0, < 5.0.0)
|
149
|
+
mongoid (7.0.2)
|
150
|
+
activemodel (>= 5.1, < 6.0.0)
|
151
|
+
mongo (>= 2.5.1, < 3.0.0)
|
152
|
+
nenv (0.3.0)
|
153
|
+
nio4r (2.3.1)
|
154
|
+
nokogiri (1.8.4)
|
155
|
+
mini_portile2 (~> 2.3.0)
|
156
|
+
notiffany (0.1.1)
|
157
|
+
nenv (~> 0.1)
|
158
|
+
shellany (~> 0.0)
|
159
|
+
pry (0.11.3)
|
160
|
+
coderay (~> 1.1.0)
|
161
|
+
method_source (~> 0.9.0)
|
162
|
+
public_suffix (3.0.3)
|
163
|
+
rack (2.0.5)
|
164
|
+
rack-test (1.1.0)
|
165
|
+
rack (>= 1.0, < 3)
|
166
|
+
rails (5.2.1)
|
167
|
+
actioncable (= 5.2.1)
|
168
|
+
actionmailer (= 5.2.1)
|
169
|
+
actionpack (= 5.2.1)
|
170
|
+
actionview (= 5.2.1)
|
171
|
+
activejob (= 5.2.1)
|
172
|
+
activemodel (= 5.2.1)
|
173
|
+
activerecord (= 5.2.1)
|
174
|
+
activestorage (= 5.2.1)
|
175
|
+
activesupport (= 5.2.1)
|
176
|
+
bundler (>= 1.3.0)
|
177
|
+
railties (= 5.2.1)
|
178
|
+
sprockets-rails (>= 2.0.0)
|
179
|
+
rails-dom-testing (2.0.3)
|
180
|
+
activesupport (>= 4.2.0)
|
181
|
+
nokogiri (>= 1.6)
|
182
|
+
rails-html-sanitizer (1.0.4)
|
183
|
+
loofah (~> 2.2, >= 2.2.2)
|
184
|
+
railties (5.2.1)
|
185
|
+
actionpack (= 5.2.1)
|
186
|
+
activesupport (= 5.2.1)
|
187
|
+
method_source
|
188
|
+
rake (>= 0.8.7)
|
189
|
+
thor (>= 0.19.0, < 2.0)
|
190
|
+
rake (10.5.0)
|
191
|
+
rb-fsevent (0.10.3)
|
192
|
+
rb-inotify (0.9.10)
|
193
|
+
ffi (>= 0.5.0, < 2)
|
194
|
+
ruby-progressbar (1.10.0)
|
195
|
+
ruby_dep (1.5.0)
|
196
|
+
rubyzip (1.2.2)
|
197
|
+
selenium-webdriver (3.14.0)
|
198
|
+
childprocess (~> 0.5)
|
199
|
+
rubyzip (~> 1.2)
|
200
|
+
shellany (0.0.1)
|
201
|
+
simple_form (4.0.1)
|
202
|
+
actionpack (>= 5.0)
|
203
|
+
activemodel (>= 5.0)
|
204
|
+
sprockets (3.7.2)
|
205
|
+
concurrent-ruby (~> 1.0)
|
206
|
+
rack (> 1, < 3)
|
207
|
+
sprockets-rails (3.2.1)
|
208
|
+
actionpack (>= 4.0)
|
209
|
+
activesupport (>= 4.0)
|
210
|
+
sprockets (>= 3.0.0)
|
211
|
+
thor (0.20.0)
|
212
|
+
thread_safe (0.3.6)
|
213
|
+
tzinfo (1.2.5)
|
214
|
+
thread_safe (~> 0.1)
|
215
|
+
websocket-driver (0.7.0)
|
216
|
+
websocket-extensions (>= 0.1.0)
|
217
|
+
websocket-extensions (0.1.3)
|
218
|
+
xpath (3.1.0)
|
219
|
+
nokogiri (~> 1.8)
|
220
|
+
|
221
|
+
PLATFORMS
|
222
|
+
ruby
|
223
|
+
|
224
|
+
DEPENDENCIES
|
225
|
+
bundler (~> 1.12)
|
226
|
+
capybara (~> 2.1)
|
227
|
+
capybara-screenshot
|
228
|
+
database_cleaner
|
229
|
+
guard
|
230
|
+
guard-minitest
|
231
|
+
jquery-rails
|
232
|
+
minitest (~> 5.0)
|
233
|
+
minitest-around
|
234
|
+
minitest-metadata
|
235
|
+
minitest-rails-capybara
|
236
|
+
minitest-reporters
|
237
|
+
mongoid
|
238
|
+
rails
|
239
|
+
rake (~> 10.0)
|
240
|
+
selenium-webdriver
|
241
|
+
simple_form_nested_fields!
|
242
|
+
|
243
|
+
BUNDLED WITH
|
244
|
+
1.16.1
|
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Tomáš Celizna
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 asgerb
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
# Simple Form Nested Fields
|
2
|
+
|
3
|
+
[](https://travis-ci.org/tomasc/simple_form_nested_fields) [](http://badge.fury.io/rb/simple_form_nested_fields) [](https://coveralls.io/r/tomasc/simple_form_nested_fields)
|
4
|
+
|
5
|
+
Nested fields helper for [`simple_form`](https://github.com/plataformatec/simple_form).
|
6
|
+
|
7
|
+
Makes it easier to handle forms with referenced/embedded models and attributes;
|
8
|
+
e.g. a document with embedded texts, a project with referenced tasks, or an
|
9
|
+
invoice with line items.
|
10
|
+
|
11
|
+
Works with standard Rails forms and SimpleForm.
|
12
|
+
|
13
|
+
## Dependencies
|
14
|
+
|
15
|
+
This gem depends on jQuery.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'simple_form_nested_fields'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install simple_form_nested_fields
|
32
|
+
|
33
|
+
If using sprockets, require the javascript in your `application.js`:
|
34
|
+
|
35
|
+
```js
|
36
|
+
//= require simple_form_nested_fields
|
37
|
+
```
|
38
|
+
|
39
|
+
and initialise the plugin like this:
|
40
|
+
|
41
|
+
```js
|
42
|
+
$(document).ready(
|
43
|
+
function() {
|
44
|
+
$(".simple_form_nested_fields").SimpleFormNestedFields()
|
45
|
+
}
|
46
|
+
)
|
47
|
+
```
|
48
|
+
|
49
|
+
## Usage
|
50
|
+
|
51
|
+
Suppose you have a model `MyDoc`, which embeds `texts`:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
# app/models/my_doc.rb
|
55
|
+
class MyDoc
|
56
|
+
include Mongoid::Document
|
57
|
+
embeds_many :texts, class_name: 'Text'
|
58
|
+
accepts_nested_attributes_for :texts, allow_destroy: true
|
59
|
+
end
|
60
|
+
|
61
|
+
# app/models/text.rb
|
62
|
+
class Text
|
63
|
+
include Mongoid::Document
|
64
|
+
field :body, type: String
|
65
|
+
embedded_in :my_doc, class_name: 'MyDoc'
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
You can then use the `nested_fields_for` helper to work with the texts in your
|
70
|
+
form:
|
71
|
+
|
72
|
+
```slim
|
73
|
+
= simple_form_for @my_doc do |f|
|
74
|
+
= f.nested_fields_for :texts
|
75
|
+
= f.submit
|
76
|
+
```
|
77
|
+
|
78
|
+
This will render the `texts/_fields` partial, in which you can use the `fields`
|
79
|
+
helper:
|
80
|
+
|
81
|
+
```slim
|
82
|
+
// app/views/my_docs/texts/_fields.html.slim
|
83
|
+
= fields.input :body
|
84
|
+
```
|
85
|
+
|
86
|
+
### Sortable
|
87
|
+
|
88
|
+
Making the nested fields sortable is straight forward.
|
89
|
+
|
90
|
+
Using our `MyDoc` and `texts` example, the models would look like this (note the
|
91
|
+
`order` on the `embeds_many` and the `position` field on the `Text`):
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
# app/models/my_doc.rb
|
95
|
+
class MyDoc
|
96
|
+
include Mongoid::Document
|
97
|
+
embeds_many :texts, class_name: 'Text', order: :position.asc
|
98
|
+
accepts_nested_attributes_for :texts, allow_destroy: true
|
99
|
+
end
|
100
|
+
|
101
|
+
# app/models/text.rb
|
102
|
+
class Text
|
103
|
+
include Mongoid::Document
|
104
|
+
field :body, type: String
|
105
|
+
field :position, type: Integer
|
106
|
+
embedded_in :my_doc, class_name: 'MyDoc'
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
Then in your `MyDoc` form simply pass the `sortable` option to the
|
111
|
+
`nested_fields_for` helper (note that in order to pass the option parameter, you
|
112
|
+
have to pass the second parameter: the collection/record object):
|
113
|
+
|
114
|
+
```slim
|
115
|
+
= simple_form_for @my_doc do |f|
|
116
|
+
= f.nested_fields_for :texts, @my_doc.texts, sortable: true
|
117
|
+
= f.submit
|
118
|
+
```
|
119
|
+
|
120
|
+
And in your `Text` fields partial add the position input:
|
121
|
+
|
122
|
+
```slim
|
123
|
+
// app/views/my_docs/texts/_fields.html.slim
|
124
|
+
= fields.input :position, as: :hidden
|
125
|
+
= fields.input :body
|
126
|
+
```
|
127
|
+
|
128
|
+
### Configuration
|
129
|
+
|
130
|
+
#### Custom partial path
|
131
|
+
|
132
|
+
You can override the default `_fields` partial lookup path as follows:
|
133
|
+
|
134
|
+
```slim
|
135
|
+
= simple_form_for @my_doc do |f|
|
136
|
+
= f.nested_fields_for :texts, nil, partial: 'my/own/path/to/fields'
|
137
|
+
= f.submit
|
138
|
+
```
|
139
|
+
|
140
|
+
#### I18n
|
141
|
+
|
142
|
+
You can change the text on the add and remove links by overriding the locale
|
143
|
+
file:
|
144
|
+
|
145
|
+
```YAML
|
146
|
+
# config/locales/simple_form_nested_fields.en.yml
|
147
|
+
en:
|
148
|
+
simple_form_nested_fields:
|
149
|
+
links:
|
150
|
+
add: 'Add %{model_name}'
|
151
|
+
remove: 'Remove'
|
152
|
+
```
|
153
|
+
|
154
|
+
### Styling
|
155
|
+
|
156
|
+
The gem has no default styling, but leaves that up to you.
|
157
|
+
For reference, here's an example markup:
|
158
|
+
|
159
|
+
```html
|
160
|
+
<div class="simple_form_nested_fields simple_form_nested_fields__texts">
|
161
|
+
<div class="simple_form_nested_fields__title">Texts</div>
|
162
|
+
<div class="simple_form_nested_fields__items">
|
163
|
+
<div class="simple_form_nested_fields__item simple_form_nested_fields__item__new">
|
164
|
+
<!-- input fields here -->
|
165
|
+
<a class="simple_form_nested_fields__link simple_form_nested_fields__link__remove">Remove</a>
|
166
|
+
</div>
|
167
|
+
</div>
|
168
|
+
<div class="simple_form_nested_fields__links">
|
169
|
+
<a class="simple_form_nested_fields__link simple_form_nested_fields__link__add">Add Title</a>
|
170
|
+
</div>
|
171
|
+
</div>
|
172
|
+
```
|
173
|
+
|
174
|
+
## Todo
|
175
|
+
|
176
|
+
* Sortable field name should be configurable (`position` by default)
|
177
|
+
|
178
|
+
## Development
|
179
|
+
|
180
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
181
|
+
|
182
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
183
|
+
|
184
|
+
## Contributing
|
185
|
+
|
186
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tomasc/simple_form_nested_fields. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
187
|
+
|
188
|
+
## License
|
189
|
+
|
190
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|