rondo_form 0.2.3 → 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 +7 -6
- data/lib/generators/rondo_form/templates/nested_rondo_controller.js +13 -11
- 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
|
|
@@ -35,7 +35,7 @@ In your `projects/_form` partial:
|
|
35
35
|
</div>
|
36
36
|
|
37
37
|
<h3 class="text-xl mt-4">Tasks</h3>
|
38
|
-
<div class="my-2" data-controller="nested-rondo">
|
38
|
+
<div class="my-2" data-controller="nested-rondo" data-nested-rondo-field-class-value="task-field">
|
39
39
|
<div data-nested-rondo-target="fieldContain">
|
40
40
|
<%= f.simple_fields_for :tasks do |task| %>
|
41
41
|
<%= render "task_fields", f: task %>
|
@@ -55,7 +55,7 @@ In your `projects/_form` partial:
|
|
55
55
|
|
56
56
|
In your `_task_fields` partial:
|
57
57
|
``` erb
|
58
|
-
<div class="
|
58
|
+
<div class="task-field">
|
59
59
|
<%= f.input :description %>
|
60
60
|
<%= f.input :done, as: :boolean %>
|
61
61
|
<%= link_to_remove_association "Remove Task", f %>
|
@@ -63,9 +63,10 @@ In your `_task_fields` partial:
|
|
63
63
|
|
64
64
|
```
|
65
65
|
|
66
|
-
|
67
|
-
- Stimulus controller
|
68
|
-
-
|
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.
|
69
70
|
|
70
71
|
## Contributing
|
71
72
|
|
@@ -2,20 +2,19 @@ import { Controller } from "@hotwired/stimulus"
|
|
2
2
|
|
3
3
|
export default class extends Controller {
|
4
4
|
static targets = ["template", "fieldContain"]
|
5
|
+
static values = { "fieldClass" : String }
|
5
6
|
|
6
7
|
addField(e) {
|
7
8
|
e.preventDefault();
|
8
9
|
|
9
|
-
|
10
|
-
let newField = this.buildNewAssociation(assoc);
|
10
|
+
const newField = this.buildNewAssociation(e);
|
11
11
|
this.fieldContainTarget.insertAdjacentHTML("beforeend", newField);
|
12
12
|
}
|
13
13
|
|
14
14
|
removeField(e) {
|
15
15
|
e.preventDefault();
|
16
|
-
|
17
|
-
|
18
|
-
let wrapperField = e.target.closest("." + wrapperClass);
|
16
|
+
const wrapperField = this.hasFieldClassValue ? e.target.closest("." + this.fieldClassValue) : e.target.parentNode;
|
17
|
+
|
19
18
|
if(e.target.matches('.dynamic')) {
|
20
19
|
wrapperField.remove();
|
21
20
|
} else {
|
@@ -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: []
|