rondo_form 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/generators/rondo_form/templates/nested_rondo_controller.js +10 -8
- data/lib/rondo_form/version.rb +1 -1
- data/lib/rondo_form/view_helpers.rb +1 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f953e44cde6292d12ee7bd3042659c45de36770dfd6f81a4590452f309faa45
|
4
|
+
data.tar.gz: 5462a299afe097966aefbf5588ac8079dd35655e9cbd0389ddce5ef4d8978ba3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8df5386a9afa39d992f3914e5f9ef7358aa2ca8fe41573e7ad56f7d87701f3c1c4d1202315d88fa1c581acf398148aa36c871f7b8c8855c54e17e040277e2175
|
7
|
+
data.tar.gz: 45e36511f96135582e1041153c3431600376943291138000023d0bd0de0965b7b0c0c024c679eb95f8e7d421504f66303ee4d324d6b1fe1f7d8ad6d2ebac9b3d
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ Install the gem and add to the application's Gemfile by executing:
|
|
10
10
|
|
11
11
|
Or inside the Gemfile add the following
|
12
12
|
|
13
|
-
$ gem 'rondo_form', '~> 0.2.
|
13
|
+
$ gem 'rondo_form', '~> 0.2.5'
|
14
14
|
|
15
15
|
Run the installation task:
|
16
16
|
|
@@ -63,10 +63,10 @@ In your `_task_fields` partial:
|
|
63
63
|
|
64
64
|
```
|
65
65
|
|
66
|
-
|
67
|
-
- Stimulus controller
|
68
|
-
-
|
69
|
-
- `data-nested-rondo-field-class-value` is used to detect the element that needs to be removed. Its value must match the class name that wraps the partial. If you do not declare it, it will default remove the closest parent element.
|
66
|
+
_Convention_:
|
67
|
+
- For convention, I named Stimulus controller `nested-rondo`. But you can change the name of Javascript file and the value of `data-controller` to match your purpose.
|
68
|
+
- `data-nested-rondo-target="fieldContain"` must be added to an element that wraps all nested fields, the new field will be appended to this element.
|
69
|
+
- `data-nested-rondo-field-class-value` is used to detect the element that needs to be removed. Its value must match the class name of an element that wraps the partial. If you do not declare it, it will default remove the closest parent element.
|
70
70
|
|
71
71
|
## Contributing
|
72
72
|
|
@@ -7,8 +7,7 @@ export default class extends Controller {
|
|
7
7
|
addField(e) {
|
8
8
|
e.preventDefault();
|
9
9
|
|
10
|
-
|
11
|
-
let newField = this.buildNewAssociation(assoc);
|
10
|
+
const newField = this.buildNewAssociation(e);
|
12
11
|
this.fieldContainTarget.insertAdjacentHTML("beforeend", newField);
|
13
12
|
}
|
14
13
|
|
@@ -24,16 +23,19 @@ export default class extends Controller {
|
|
24
23
|
}
|
25
24
|
}
|
26
25
|
|
27
|
-
buildNewAssociation(
|
28
|
-
|
29
|
-
|
26
|
+
buildNewAssociation(element) {
|
27
|
+
const assoc = element.target.dataset.association;
|
28
|
+
const assocs = element.target.dataset.associations;
|
29
|
+
const content = this.templateTarget.innerHTML;
|
30
|
+
|
31
|
+
let regexpBraced = new RegExp('\\[new_' + assoc + '\\](.*?\\s)', 'g');
|
30
32
|
let newId = new Date().getTime();
|
31
|
-
let newContent = content.replace(regexpBraced, '[' + newId + ']');
|
33
|
+
let newContent = content.replace(regexpBraced, '[' + newId + ']$1');
|
32
34
|
|
33
35
|
if (newContent == content) {
|
34
36
|
// assoc can be singular or plural
|
35
|
-
regexpBraced = new RegExp('\\[new_' +
|
36
|
-
newContent = content.replace(regexpBraced, '[' + newId + ']');
|
37
|
+
regexpBraced = new RegExp('\\[new_' + assocs + '\\](.*?\\s)', 'g');
|
38
|
+
newContent = content.replace(regexpBraced, '[' + newId + ']$1');
|
37
39
|
}
|
38
40
|
return newContent;
|
39
41
|
}
|
data/lib/rondo_form/version.rb
CHANGED
@@ -48,6 +48,7 @@ module RondoForm
|
|
48
48
|
|
49
49
|
html_options[:class] = [html_options[:class], "add_fields"].compact.join(' ')
|
50
50
|
html_options[:'data-association'] = association.to_s.singularize
|
51
|
+
html_options[:'data-associations'] = association.to_s.pluralize
|
51
52
|
html_options[:'data-action'] = "click->nested-rondo#addField"
|
52
53
|
|
53
54
|
new_object = f.object.class.reflect_on_association(association).klass.new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rondo_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hungle00
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -89,7 +89,7 @@ licenses:
|
|
89
89
|
metadata:
|
90
90
|
homepage_uri: https://github.com/hungle00/rondo_form
|
91
91
|
source_code_uri: https://github.com/hungle00/rondo_form
|
92
|
-
post_install_message:
|
92
|
+
post_install_message:
|
93
93
|
rdoc_options: []
|
94
94
|
require_paths:
|
95
95
|
- lib
|
@@ -104,8 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
rubygems_version: 3.
|
108
|
-
signing_key:
|
107
|
+
rubygems_version: 3.4.10
|
108
|
+
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: Cocoon, but with Stimulus JS
|
111
111
|
test_files: []
|